Default value that uses the number in previous record plus 1 (1 Viewer)

tinher

Registered User.
Local time
Yesterday, 20:55
Joined
May 11, 2019
Messages
30
I have done this before and I cannot remember what I did.
I used a DLOOKUP and grabbed the number in previous record field InvNo and added 1 to it.

So if last record InvNo was 14750 then in new record InvNo was defaulted to 14751

I can use this code to copy forward text fields. I thought I could modify it to update my InvNo field but I cannot figure it out. I need this in the default value of the InvNo field.

Private Sub NewRecClockIn_Click()
Dim ID As Long

ID = QuoteID
DoCmd.GoToRecord , , acNewRec
location = DLookup("location", "tblUserQuotes", "QuoteID=" & ID)
UserFK = DLookup("UserFK", "tblUserQuotes", "QuoteID=" & ID)
cmdClose.SetFocus
End Sub

Thank you.
 

tinher

Registered User.
Local time
Yesterday, 20:55
Joined
May 11, 2019
Messages
30
I figured it out. I just need to explain it here so thank You.

Here is what I used.

I created a button and added this code to on click event.

Private Sub Command24_Click()
Dim ID As Long

ID = DMax("INoID", "tblInvNo")
DoCmd.GoToRecord , , acNewRec
InvNo = DLookup("InvNo", "tblInvNo", "INoID=" & ID) + 1
Invname.SetFocus


End Sub

Thanks
 

tinher

Registered User.
Local time
Yesterday, 20:55
Joined
May 11, 2019
Messages
30
I actually found a youtube video that explained this. I only added the +1 at end of code.

Did not want to take credit like I know how to program code or anything.

Thanks.
 

missinglinq

AWF VIP
Local time
Yesterday, 23:55
Joined
Jun 20, 2003
Messages
6,423
Important question: Is this being done in a one-off database...i.e. with only a single user...or is it in a multi-user environment?

This is important in order to prevent multiple records have the same InvNo!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom