Unsure how to do this

Results 1 to 2 of 2

Thread: Unsure how to do this

  1. #1
    Join Date
    Dec 1969

    Default Unsure how to do this

    I have a series of forms that get entered as 1 record in an Access db. On the second form I&#039m inserting the info from the first form. At this point I am using an autonumber field in the Access db to generate an ID for that record. What I would like to do is pull that ID# from the db as soon as it&#039s created and pass it along to all of the other pages in the series.<BR><BR>What I have tried is after the INSERT INTO statement setting the value of ID=rs("ID") and get an error message of "type mismatch".<BR><BR>Never done this before and would appreciate any help.

  2. #2
    peterjl@austec.net.au Guest

    Default RE: Unsure how to do this

    I presume you are building an sql command string and executing it via the Connection.Execute method. You can never guarrantee that you can retreive the ID for the row you have just inserted. Another user may have submitted a record at the same time and therefore the record you have just inserted will not be the last record. <BR>Instead use the recordset.AddNew method to insert the contents of the first form. EG:<BR><BR>&#060;%<BR>rs.addnew<BR>rs("Fld1")=requ est.form("fld1")<BR>rs("Fld1")=request.form("fld1" )<BR>rs("Fld1")=request.form("fld1")<BR>rs.update< BR>ID=rs("ID") <BR>%&#062;<BR>The Rs.Update command inserts the fields you have set into the dbase and gets a copy of the record. So you are then guaranteed to have the ID of the record you just inserted.<BR><BR>Then you can include the value of ID as an hidden form variable or Session variable to pass it to subsequent form pages.<BR><BR>Alternatively collect all the data from each form and pass it all as hidden form fields or session vars to each form page, then insert all fields to the database after the last form page is submitted.

Posting Permissions

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