reference from field?

AN60

Registered User.
Local time
Today, 18:54
Joined
Oct 25, 2003
Messages
283
Hi all, it's been a while since I have done anything to my db's in Access so I'm a little rusty.
I have a sub form with a Field, in which I enter ID's taken from physical forms(paper forms). The ID's are in booklets with increasing order throughout each booklet. I want to have MyField show the last ID number entered + one. Can someone push me in the right direction, where should I put the code, in the query or in myfield itself, & what do I need to do it?
 
Copy and Paste this line directly into the small property window box for the Default Value of MyField:

Code:
Nz(DLast("[[COLOR="Red"][I]yourTableRecordIDFieldName[/I][/COLOR]]","[COLOR="Red"][I]yourTableName[/I][/COLOR]"),0)+1

Of course, replace the items in red italic with the proper names.

The Nz() function is required if there are no records at all in Table. We need something to add 1 to.

The DLast() function is configured to pull the ID number of the Last record saved to Table. We then simply add 1 to that ID number.

See the Attached Image.

.
 

Attachments

  • DefaultValue.png
    DefaultValue.png
    8.3 KB · Views: 108
Last edited:
CyberLynx
Thanks for your help. I tried your suggestion but it returnes a value of 1 & not the last enteres number, as desired. Note that I don't want the table ID, but the ID of my physical written form, in this case the field has a name of DecNumber. I might have confused you in my first post.
 
I would use DMax to get the last number and add one to it, if it is indeed a number.
 
Boblarson
Thanks, I used Dmax as follows, & it retreived the maximum number;
=DMax("[MyField]","[MyTable]")
Note that I didn't add one to the above because I was just testing things at this stage.

The problem I now have is that because these physical paper forms are in booklets they only follow in numerical order until we get a new book, then the numbers might be less than the previous book!! I really need to get MyField to show the last number as opposed to the maximum number so I just tried =DLast("[myfield]","[mytable]") & I get the last number I entered:). I'm now off to do some fine tuning.
Thanks to all for your help.;)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom