Send tblName variable to function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,
I have function that finds the next record in a table. I use this function
to auto-generate the next record number (in a non-Autonumber field) in
several tables - although I have to have a separate function for each table.

The function uses the
dbs.OpenRecordSet ("tblTable1") code.
I would like to re-use this function by sending the Table Name as a variable
to the function - avoiding duplicity of the code. How do I do this?

Thanks in Advance
Anand
 
This should do it:

Public Function NextNumber(strTable As String, strField As String, _
Optional strCriteria As String) As Long
On Error Resume Next
Dim lngMax As Long

lngMax = Nz(DMax(strField, strTable, strCriteria), 0&)
NextNumber = lngMax + 1&
End Function

Example for field ID in table Table1:
? NextNumber ("Table1", "ID")
 
Back
Top