Full Version: dlookup to select last record in table
UtterAccess Forums > Microsoft® Access > Access Forms
mhearnsww
I'm trying to select the last record in the table via dlookup. Below is the code i've got so far.
im IntNum As Integer
Dim InvNumHold As Integer
InvNumHold = DLookup("[InvoiceNumber]", "tblMeteredInvoice")
IntNum = InvNumHold + 1
Me!txtInvoiceNum = IntNum
Me!txtInvoiceNum = Format(IntNum, "00000")
This code is basically taking the last invoice number and then increment it by 1, so that will be used for the next invoice number. I dont know the criteria that would be used to look for the last record in the table, i tried the 'MaxRecords' but that didnt work, i couldnt see anything else appropriate to use for it.
Any suggestions would be greatly appreciated.
ScottGem
You want a DMax
e!txtInvoiceNum = DMax("[InvoiceNumber]", "tblMeteredInvoice") + 1
Set the format of the control in the properties to "00000".
cheekybuddha
Hi,

If the 'Last' record is the highest Invoice number then try simply:

Me.txtInvoiceNum = Format(DMax("InvoiceNumber", "tblMeteredInvoice") + 1, "00000")

hth,

d
Edited by: cheekybuddha on Thu May 4 10:13:13 EDT 2006.
mhearnsww
Thank You, that worked perfectly.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.