Hello! I am expanding my db to auto-assign unique ids to new records appended to a Datasheet form. The unique ids should be in sequence, retrieved from another database (EXT) that stores existing records (DMAX + 1). If the last record from EXT is 12345, then the first record on my from should be 12346 and so forth. How do I create a For Each statement that calls to EXT and retrieves the last record, then updates my records accordingly. The ADJ_ID is the field I want auto-updated on my datasheet form. The dbo_RM00101 table is the table that has the CUSTNMBR that is storing existing records.
This is what I have so far:
Private Sub Form_DblClick(Cancel As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim ADJ_ID As String
Dim CLICK As Form_frmUserInputADJ1
For Each CLICK in ?
Last_ID = DMax("[CUSTNMBR]", "dbo_RM00101", "[CUSTNMBR] like 'AD000*'")
Set db = CurrentDb
Set rst = db.OpenRecordset("Select [CUSTNMBR] from dbo_RM00101 where [CUSTNMBR] like 'AD000*'", dbOpenSnapshot)
Do Until rst.EOF
next_ID = "AD000" & Right(Last_ID, 8) + 1
next_ID = Me.ADJ_ID.Value
This_ID = next_ID
rst.MoveNext
Loop
Set rst = Nothing
Set db = Nothing
End Sub
This is what I have so far:
Private Sub Form_DblClick(Cancel As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim ADJ_ID As String
Dim CLICK As Form_frmUserInputADJ1
For Each CLICK in ?
Last_ID = DMax("[CUSTNMBR]", "dbo_RM00101", "[CUSTNMBR] like 'AD000*'")
Set db = CurrentDb
Set rst = db.OpenRecordset("Select [CUSTNMBR] from dbo_RM00101 where [CUSTNMBR] like 'AD000*'", dbOpenSnapshot)
Do Until rst.EOF
next_ID = "AD000" & Right(Last_ID, 8) + 1
next_ID = Me.ADJ_ID.Value
This_ID = next_ID
rst.MoveNext
Loop
Set rst = Nothing
Set db = Nothing
End Sub