Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected result after .UPDATE in VB6

Status
Not open for further replies.

Jimdeb03

IS-IT--Management
Dec 10, 2002
89
US
Set gwrkMain = CreateWorkspace("", "admin", "", dbUseJet)
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top