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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last inserted record not found

Status
Not open for further replies.

PinnacleDan

Programmer
Jun 10, 2004
9
US
I was transfered to this forum and hope I am in the right category.
I have a VB program that clears an Access table then, in a loop, inserts several records into it.

Code:
Set WK = CreateWorkspace("", "admin", "", dbUseJet)
Set DB2 = WK.OpenDatabase(MasterFile)
SQL = "Delete * From Materials "
DB2.Execute SQL, dbFailOnError 
Do While Not RSmatl.EOF
 SQL="Insert Into Materials (JobCode, Item)"
 SQL=SQL & "Values ('" & CurJob & "','" & CurItem & "')" 
 DB2.Execute SQL, dbFailOnError
 RSmatl1.MoveNext
Loop
I then load the table into a datagrid for review.

Code:
SQL = "Select * From Materials "
frmRpt2.AdodcR1.RecordSource = SQL
frmRpt2.AdodcR1.Refresh
frmRpt2.DataGrid1.Refresh
The problem is that the last record inserted does not display in the grid. I added a 1-second delay after the insert and the problem seems resolved. However, I am sure this is not the right way to ensure the insert is complete before I read the table. Any help?
 
turn the hourglass on at the start of the procedure and off at the end. Take a look at docmd.hourglass
 
I am not creating code in Access. I am working with VB. I think I am in the wrong forum. I'll try "Visual Basic(Microsoft) Databases Forum".

Thanks anyway
 
What about the DoEvents function ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Actually, I tried the DoEvents with no success. Only a 1-second pause does the trick.

Thank you. I think my answer is in another forum where they talk about asyncronous database functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top