Set gwrkMain = CreateWorkspace("", "admin", "", dbUseJet)
Set gdbsPubs = gwrkMain.OpenDatabase(DATABASENAME)
Set rstRecordset = gdbsPubs.OpenRecordset("KTABLE"
I have an issue with the above VB6 code when accessing an Access DB. The above table KTABLE is linked to three other tables. After creating the Recordset, the intent is to add a new record and recall a field from that new record, which coincidentally happens to be a linked field to another table. Well, the .AddNew command adds a record after executing .Update, as expected.
However when Debugging and monitoring the !KP field, after the .Update command is fired, the !KP field doesn't reflect the last record in the Recordset. The debug line 'Debug.Print !KP' just above .Update reflects the new record but once .Update is crossed, !KP changes to another value. Also, !KP is an AutoNumber.
My fix was to add the line '.Bookmark = .LastModified' where !KP reflects the last record. I'm wondering if something is missing since this code works fine in the lab but not in the field, usually. Would this table having relationships with other tables factor into the problem?
Set gdbsPubs = gwrkMain.OpenDatabase(DATABASENAME)
Set rstRecordset = gdbsPubs.OpenRecordset("KTABLE"
Code:
With rstRecordset
.MoveLast
Debug.Print !KP
DateCont = !SDate
.AddNew
!KitPNum = UDT.KP
!BSze = UDT.BSize
!Bs = Bs
!SDate = Now
!KP = KSssn
Debug.Print !KP
.Update
.Bookmark = .LastModified
.MoveLast
KSpk = !KP
KSssn = !KP
.Close
End With
I have an issue with the above VB6 code when accessing an Access DB. The above table KTABLE is linked to three other tables. After creating the Recordset, the intent is to add a new record and recall a field from that new record, which coincidentally happens to be a linked field to another table. Well, the .AddNew command adds a record after executing .Update, as expected.
However when Debugging and monitoring the !KP field, after the .Update command is fired, the !KP field doesn't reflect the last record in the Recordset. The debug line 'Debug.Print !KP' just above .Update reflects the new record but once .Update is crossed, !KP changes to another value. Also, !KP is an AutoNumber.
My fix was to add the line '.Bookmark = .LastModified' where !KP reflects the last record. I'm wondering if something is missing since this code works fine in the lab but not in the field, usually. Would this table having relationships with other tables factor into the problem?