-
I am using a ADO recordset, in which one field is AudotNumber. When I add a new record to the recordset, after updating the recordset, I want to display the value of AutoNumber field, using Msgbox. But this does not show it by any mean. Please help me.
Here is an example code
' These are the fields in the cursor
' StudentID AutoNumber
' Name Character(30)
' FName Character(30)
' Caste Character(20)
' I am using MS-Access database.
RS.Addnew
RS.Fields("Name")=txtName
RS.Fields("FName")=txtFName
RS.Fields("Caste")=txtCaste
RS.Update
MsgBox RS.Fields("StudentID")
But a blank MSBOX is is displayed. How can I solve this problem.
Thanks in advance.
-
Code:
RS.Addnew
RS.Fields("Name")=txtName
RS.Fields("FName")=txtFName
RS.Fields("Caste")=txtCaste
RS.Update
RS.CLOSE
RS.OPEN "SELECT MAX(StudentID) as MAXID FROM TABLE",DB
Msgbox RS.Fields("MAXID")
Hope this helps
-
You could also do this as well.
dim studentId as long
RS.Addnew
studentId = RS.Fields("StudentID")
RS.Fields("Name")=txtName
RS.Fields("FName")=txtFName
RS.Fields("Caste")=txtCaste
RS.Update
Msgbox studentId
-