PDA

Click to See Complete Forum and Search --> : I want to know value of AutoNumber field after update in ADO model.


malnus
Jul 11th, 2000, 07:08 AM
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.

Negative0
Jul 11th, 2000, 07:15 AM
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

Jimmer
Jul 11th, 2000, 08:07 AM
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

Clunietp
Jul 11th, 2000, 11:10 AM
http://forums.vb-world.net/showthread.php?threadid=22048