A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

subform and autonumbering



 
 
Thread Tools Display Modes
  #1  
Old July 20th, 2004, 02:17 PM
Nancy
external usenet poster
 
Posts: n/a
Default subform and autonumbering

Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy
  #2  
Old July 20th, 2004, 02:41 PM
Roger Carlson
external usenet poster
 
Posts: n/a
Default subform and autonumbering

You can use the DMax() function to accomplish this. On website, see sig
below, there is a small sample database called "FormSubform.mdb" which
illustrates how.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org

"Nancy" wrote in message
...
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy



  #3  
Old July 20th, 2004, 02:48 PM
Sandra Daigle
external usenet poster
 
Posts: n/a
Default subform and autonumbering

Hi Nancy,

I generally use code like the following:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.LineNum = Nz(DMax("Linenum", "tblQuoteDetails", "QuoteNumber=" &
Me.Parent.QuoteNumber), 0) + 1
End Sub

Where "tblQuoteDetails" is the name of the table for Quote Details. If you
do this in the BeforeInsert event you have to get the PK field (QuoteNumber)
from the parent form because it will not have been copied into the subform
record when the code executes.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Nancy wrote:
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy



  #4  
Old July 20th, 2004, 04:32 PM
quest4
external usenet poster
 
Posts: n/a
Default subform and autonumbering


-----Original Message-----
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related

by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy
.

Try this in the BeforeUpDate event of the LineNo:
If IsNull(Me!LineNo) Then
'Sequential numbering for Items entered
Me!LineNo= Nz(DMax
("[LineNo]", "YourTable", "[YourPKey] = " & Me!YourPKey),
0) + 1
This works for me. This kind of stuff is better answered
over at Utter Access or Tek-Tips. You are just lucky I am
hunting for something and happened across this. Good luck.
End If
  #5  
Old July 20th, 2004, 05:30 PM
external usenet poster
 
Posts: n/a
Default subform and autonumbering

Hi Sandra,

I've tried copying your code as show below on the subform
beforeinsert event.


Private Sub Form_BeforeInsert(Cancel As Interger)
Me!Line# = Nz(DMax("Line#", "tbl_Quote Line Item
File", "Quote#=" & Me.Parent.Quote#), 0) + 1

End Sub

However, I get the following error message when I try to
use the form:

The expression before insert you entered as the event
property setting produced the following error: Can't find
the project or library.

Do you have any idea of what I have done wrong?
I really appreciate your help.

Best regards,
Nancy

-----Original Message-----
Hi Nancy,

I generally use code like the following:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.LineNum = Nz(DMax

("Linenum", "tblQuoteDetails", "QuoteNumber=" &
Me.Parent.QuoteNumber), 0) + 1
End Sub

Where "tblQuoteDetails" is the name of the table for

Quote Details. If you
do this in the BeforeInsert event you have to get the PK

field (QuoteNumber)
from the parent form because it will not have been copied

into the subform
record when the code executes.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Nancy wrote:
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related

by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy



.

  #6  
Old July 20th, 2004, 07:39 PM
Tom Ross
external usenet poster
 
Posts: n/a
Default subform and autonumbering

Thanks Sandra. I needed that too

"Sandra Daigle" wrote in message
...
Hi Nancy,

I generally use code like the following:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.LineNum = Nz(DMax("Linenum", "tblQuoteDetails", "QuoteNumber=" &
Me.Parent.QuoteNumber), 0) + 1
End Sub

Where "tblQuoteDetails" is the name of the table for Quote Details. If you
do this in the BeforeInsert event you have to get the PK field

(QuoteNumber)
from the parent form because it will not have been copied into the subform
record when the code executes.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Nancy wrote:
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy





  #7  
Old July 20th, 2004, 07:57 PM
Sandra Daigle
external usenet poster
 
Posts: n/a
Default subform and autonumbering

Hi Nancy,

Check your references - in the VB Editor (not in debug mode) click
Tools-References. Look for one that is marked Missing. Check Doug Steele's
article for tips on how to resolve reference problems:
http://members.rogers.com/douglas.j....nceErrors.html

Another possible issue is with your field/Control Names. When you include
spaces and/or special characters in a name you must wrap the entire name in
square brackets:

Me![Line#] = Nz(DMax("[Line#]", "[tbl_Quote Line Item File]", "[Quote#]=" &
Me.[Parent.Quote#]), 0) + 1

This is a good reason for avoiding these kinds of names - I prefer names
like LineNum or LineNo. Easy to read and easy to type.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


wrote:
Hi Sandra,

I've tried copying your code as show below on the subform
beforeinsert event.


Private Sub Form_BeforeInsert(Cancel As Interger)
Me!Line# = Nz(DMax("Line#", "tbl_Quote Line Item
File", "Quote#=" & Me.Parent.Quote#), 0) + 1

End Sub

However, I get the following error message when I try to
use the form:

The expression before insert you entered as the event
property setting produced the following error: Can't find
the project or library.

Do you have any idea of what I have done wrong?
I really appreciate your help.

Best regards,
Nancy

-----Original Message-----
Hi Nancy,

I generally use code like the following:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.LineNum = Nz(DMax

("Linenum", "tblQuoteDetails", "QuoteNumber=" &
Me.Parent.QuoteNumber), 0) + 1
End Sub

Where "tblQuoteDetails" is the name of the table for Quote Details.
If you do this in the BeforeInsert event you have to get the PK
field (QuoteNumber) from the parent form because it will not have
been copied into the subform record when the code executes.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Nancy wrote:
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy



.



  #8  
Old July 20th, 2004, 07:57 PM
Sandra Daigle
external usenet poster
 
Posts: n/a
Default subform and autonumbering

You're welcome - glad to help.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Tom Ross wrote:
Thanks Sandra. I needed that too

"Sandra Daigle" wrote in message
...
Hi Nancy,

I generally use code like the following:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.LineNum = Nz(DMax("Linenum", "tblQuoteDetails",
"QuoteNumber=" & Me.Parent.QuoteNumber), 0) + 1
End Sub

Where "tblQuoteDetails" is the name of the table for Quote Details.
If you do this in the BeforeInsert event you have to get the PK
field (QuoteNumber) from the parent form because it will not have
been copied into the subform record when the code executes.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Nancy wrote:
Hi,

I have a quote form (with header info) and a related
subform with line item detail. The 2 forms are related by
the quote# which is the primary field in the main quote
form and autonumbered. I need to automatically number
each line item on the subform as data is entered.
Example: each quote# can have multiple line item #s
1,2,3,4, etc. Does anyone have an idea on how I can
accomplish this?

Thanks for your help!
Nancy



  #9  
Old July 23rd, 2004, 06:33 PM
grep
external usenet poster
 
Posts: n/a
Default subform and autonumbering

See?! She's "just lucky" he was passing through. The rest of you folks
in here - you know, the one's who've been posting all that code -
obviously don't know jack!

Just lucky... sheesh!


quest4 wrote:

This works for me. This kind of stuff is better answered
over at Utter Access or Tek-Tips. You are just lucky I am
hunting for something and happened across this. Good luck.
End If

  #10  
Old August 13th, 2004, 08:07 PM
Ted
external usenet poster
 
Posts: n/a
Default subform and autonumbering

is it just me or has anyone else found they can't log in to 'Tek-Tips' (or
for that matter even re-join) that forum? 'they' don't even respond to the
several email attempts at expressing that.

but, i digress; given that i have two correlated test forms ("master" and
"child") having a common field called "linker" and wherein the sub-form
("child") contains a field called "record" which i'd like to have
autonumbered, can anybody reading this tell me why the modified version of
the code posted earlier doesn't seem to have quite the same outcome?
basically, nothing happens as i scroll through the database and
(interestingly) the add record functionality of the sub-form's is stippled
out.





"grep" wrote:

See?! She's "just lucky" he was passing through. The rest of you folks
in here - you know, the one's who've been posting all that code -
obviously don't know jack!

Just lucky... sheesh!


quest4 wrote:

This works for me. This kind of stuff is better answered
over at Utter Access or Tek-Tips. You are just lucky I am
hunting for something and happened across this. Good luck.
End If


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.