hi,
i want to display last ID in my form field, below code does not work. any solution ?
Private Sub Form_Load()
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
selectQuery = "SELECT ID FROM myTable"
Set rs = CurrentDb.OpenRecordset(selectQuery)
rs.MoveLast
lastRec = rs("ID")
Me.fldRptNo.Value = lastRec
MsgBox lastRec
'get newly inserted record ID (autonumber)
'rs.Move 0, rs.LastModified
'newID = rs("ID")
rs.Close
Set rs = Nothing
End Sub
i want to display last ID in my form field, below code does not work. any solution ?
Private Sub Form_Load()
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
selectQuery = "SELECT ID FROM myTable"
Set rs = CurrentDb.OpenRecordset(selectQuery)
rs.MoveLast
lastRec = rs("ID")
Me.fldRptNo.Value = lastRec
MsgBox lastRec
'get newly inserted record ID (autonumber)
'rs.Move 0, rs.LastModified
'newID = rs("ID")
rs.Close
Set rs = Nothing
End Sub