Results 1 to 3 of 3

Thread: RecordSet.AddNew

  1. #1
    Neils Guest

    Default RecordSet.AddNew

    I have the following code, which should insert a new record into the table, and then grab the identity column, but instead of getting the value of the identity column, it gets zero every time (I&#039;m using sql server 7.0):<BR><BR>objConnection.Open DB_CONN<BR> <BR> With objRecordSet<BR> <BR> .Open "EmailArchive", objConnection, adOpenKeyset, adLockOptimistic, adCmdTable<BR> <BR> .AddNew<BR> <BR> .Fields("MessageBody") = strBody<BR> .Fields("MessageSubject") = strSubject<BR> .Fields("DateSent") = Date<BR> .Fields("TimeSent") = Time<BR> .Fields("ProductOfferTypeID") = intPOTypeID<BR> .Fields("RecipientCount") = intRecipientCount<BR> .Fields("TypeName") = strPOTypeName<BR> <BR> .Update<BR> <BR> ArchiveMessage = .Fields("MessageID")<BR> <BR> .Close<BR> <BR> End With

  2. #2
    Join Date
    Dec 1969

    Default RE: RecordSet.AddNew

    I had that problem before. You can fix it by adding:<BR><BR>.MovePrevious<BR>.MoveNext<BR><BR>A fter .Update and then get the new ID. I don&#039;t know why it doesn&#039;t work if you don&#039;t do that, but this fixes it.<BR><BR>

  3. #3
    neils Guest

    Default RE: RecordSet.AddNew

    I also had to change the cursor type to adOpenDynamic, but now it works great. Thanks.

Posting Permissions

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