Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,399 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,232 people online right now. Registration is fast and FREE... Join Now!




get last record's ID and use it for New Record

 
Reply to this topicStart new topic

get last record's ID and use it for New Record

Nolan
post 28 Aug, 2008 - 03:04 PM
Post #1


New D.I.C Head

*
Joined: 12 Sep, 2007
Posts: 47


My Contributions


I do not want to use an Autonum data type for my Project_ID field, but I would like to keep them incremented by 1.
I think the best way to do this is to examine the LAST record's Project_ID, store it, add '1' to it, then move to a NEW record and use that new value in the File_Num field.

CODE

'ensure that the data loads - seemed to be an issue so we will force it

'Me.Refresh

'declare variable to store LastNumber from Project_ID
Dim LastNum As Integer

'declare and populate stdocname to satisfy DoCmd
stDocName = "frm_NewProject"
'move to last record
DoCmd.GoToRecord acDataForm, stDocName, acLast
'load variable with value from File_Num
LastNum = Me.File_Num.Value
'increment LastNum
LastNum = LastNum + 1
'go to New record
DoCmd.GoToRecord acDataForm, stDocName, acNewRec
'populate File_id with new value
Me.File_Num.Value = LastNum


The current result is an Access error message "The expression you entered has a field, control, or property name that Access can't find". When I debug it takes me to the line "LastNum = Me.File_Num.Value" and LastNum has a value of 0, but Me.file_num.value has a value of 2633 (the correct value for the 'last' record).

MSKB has nothing helpful.

Any suggestions???
Thanks!
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 29 Aug, 2008 - 02:12 AM
Post #2


D.I.C Addict

Group Icon
Joined: 6 Oct, 2006
Posts: 517



Thanked 3 times

Dream Kudos: 125
My Contributions


And why exactly dont you want to use an autonum field?
User is offlineProfile CardPM

Go to the top of the page

Nolan
post 29 Aug, 2008 - 10:45 AM
Post #3


New D.I.C Head

*
Joined: 12 Sep, 2007
Posts: 47


My Contributions


I just don't.
Do you have any suggestions?
Thanks.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 07:44AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month