Does anyone have any suggestions as to a good way to go about getting
that number.
The @@IDENTITY function works if you are using ADO, but only if you know
that nobody has inserted another record into _any_ table in the meantime.
The safest answer is to use a bit of DAO to collect the number in one go:
Public Sub NewRecordIDNumber() As Long
' there is no error trapping in this.
' you might also want to pass required values as
' parameters to the function too.
Dim db As Database
Dim rs as Recordset
Dim strSQL as String
Dim dwNumber as Long
' don't want any records, and only bare minimum of fields
strSQL = "SELECT ANField, RequiredField " & vbNewLine & _
"FROM MyTable " & vbNewLine & _
"WHERE False"
' get an empty recordset
Set db = CurrentDB()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
' add a new record
rs.AddNew
' don't forget to initialise any required fields that don't
' have a DV defined.
rs!RequiredField = "Some Value"
' get the number we want
dwNumber = rs!ANField
' save it
rs.Update
' all done
rs.Close
' return the value
NewRecordIDNumber = dwNumber
End Function
Hope that helps
Tim F