Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max of recordset (Recordset Newbie) 1

Status
Not open for further replies.

buzzboychicago

Programmer
Sep 20, 2004
34

Below is some code that I want to use to programatically add data to a table. However, where it says "Insert Calculated Field Here" I want to find the max of the INVOICERESEND table. Not sure what the syntax would be of if I have to use some sort of SQL statement.



Private Sub Command2_Click()
Dim db As Database
Dim rst1 As Recordset
Dim newnumber As Long

Set db = CurrentDb
Set rst1 = db.OpenRecordset("invoiceresend")

rst1.AddNew
rst1!invoice = [INSERT CALCULATED VARIABLE HERE]
rst1.Update
rst1.Close
db.Close

End Sub
 
Have a look to the DMax function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi!

You can use the DMax function:

rst1!invoice = DMax("invoice", "invoiceresend") + 1

I added the + 1 because it looks like some sort of invoice number so it shouldn't be repeated.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Thanks for your help jebry.

That worked.

Can I use a SQL string to asign data to variables or manipulate a recordset?
 
Have a look at the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top