Wierd problem adding record to Access db

Results 1 to 2 of 2

Thread: Wierd problem adding record to Access db

  1. #1
    Jeff Paar Guest

    Default Wierd problem adding record to Access db

    I&#039m experiencing a wierd problem Inserting a record into an Access97 db via ADO/ASP. I insert a record into a table, then immediately want to grab the new primary key value from an autonumber field. Problem is that the record addition does not seem to be "completed" by the time I grab the primary key value,and returns an EOF error. Here&#039s some annotated code:<BR><BR>================<BR>&#039 insert a new record<BR>strSQL = "Insert into MyTable (Field1, Field2) " & _<BR>"Values ("MyValue1", "MyValue2")"<BR>cn.execute strSQL<BR><BR>&#039 now grab primary key from the newly added record<BR>strSQL = "Select PrimaryKey from MyTable " & _<BR>"where Field1 = "MyValue1" and Field2 = "MyValue2"<BR>rs.open strSQL, cn<BR><BR>&#039here is where the error occurs if the record hasn&#039t completely added...<BR>lngPrimaryKey = rs("PrimaryKey")<BR>================<BR><BR>if you put some sort of "pause" code in here, like opening and closing the recordset a few times, the inserted record adds "completely" and you can then assign lngPrimaryKey.<BR><BR>Using SQLServer you can accomplish this using @@Identity and a .nextrecordset technique. Anyone got any ideas on how to fix this problem without having to stick some kind of "pause" code in here enabling Access to fully insert the new record??<BR><BR>Thanks,<BR>-Jeff<BR>

  2. #2
    Join Date
    Dec 1969

    Default ASPFAQs (see top of page) #79


Posting Permissions

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