Results 1 to 4 of 4

Thread: I want to know value of AutoNumber field after update in ADO model.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Hyderabad, Sindh, Pakistan
    Posts
    2

    Red face

    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.
    Hashim

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    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

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85
    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

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width