Hi,
I am writing a Wizard type approach for non Access gurus to extract data from a database. Each form drills further down into the data with only those records based on previous forms being presented. I have got it all generally working but have this annoying problem.
The first form asks the user to choose the Cruise(s) from a list (16 items at present). When the NEXT button on this form is pressed each item chosen in the Listbox is placed in a table then two queries are run, the first deletes all the old data from a table and the second appends new records to that table based on the Cruises selected and a table that lists the Cruise, Stations sampled and their Latitude and Longitude. This table is then presented in the next form. So the final lines in my code when the NEXT button is pressed on the first form are:
DoCmd.SetWarnings False
'Now clear table "SelCruise Data"
DoCmd.OpenQuery "Clear CruiseSel Data Query", acViewNormal
'Now run query linking "SelCruise" which has selected Cruises and "Cruise Station" table
'to put Cruise, Station, Latitude and Longitude into table "SelCruise Data"
DoCmd.OpenQuery "CruiseSel Data Query", acViewNormal
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm ("Get Stations Make Table"
When the form "Get Stations Make Table" appears the data does not reflect the Cruise(s) chosen, in fact it is from the chosen Cruise(s) from the selection before the present selection, in other words it appears that the second query has started before the first completed. To test this I changed my code to:
DoCmd.SetWarnings False
'Now clear table "SelCruise Data"
DoCmd.OpenQuery "Clear CruiseSel Data Query", acViewNormal
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
'Now run query linking "SelCruise" which has selected Cruises and "Cruise Station" table
'to put Cruise, Station, Latitude and Longitude into table "SelCruise Data"
DoCmd.OpenQuery "CruiseSel Data Query", acViewNormal
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm ("Get Stations Make Table"
When this code is run the second form gets exactly the data from the Cruise(s) I want. If I change the Pause time to 2 seconds, it fails.
This is all run on a Pentium 600 MHz machine on Windows 2000 with the database on my local hard drive so there is no lag with using netword drives.
Is there some way to force a wait until one query is completed before the next is run, I thought Access/VBA would do this automatically i.e. wait until the actions from one line of code is completed before the next is run.
Thanks
George
I am writing a Wizard type approach for non Access gurus to extract data from a database. Each form drills further down into the data with only those records based on previous forms being presented. I have got it all generally working but have this annoying problem.
The first form asks the user to choose the Cruise(s) from a list (16 items at present). When the NEXT button on this form is pressed each item chosen in the Listbox is placed in a table then two queries are run, the first deletes all the old data from a table and the second appends new records to that table based on the Cruises selected and a table that lists the Cruise, Stations sampled and their Latitude and Longitude. This table is then presented in the next form. So the final lines in my code when the NEXT button is pressed on the first form are:
DoCmd.SetWarnings False
'Now clear table "SelCruise Data"
DoCmd.OpenQuery "Clear CruiseSel Data Query", acViewNormal
'Now run query linking "SelCruise" which has selected Cruises and "Cruise Station" table
'to put Cruise, Station, Latitude and Longitude into table "SelCruise Data"
DoCmd.OpenQuery "CruiseSel Data Query", acViewNormal
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm ("Get Stations Make Table"
When the form "Get Stations Make Table" appears the data does not reflect the Cruise(s) chosen, in fact it is from the chosen Cruise(s) from the selection before the present selection, in other words it appears that the second query has started before the first completed. To test this I changed my code to:
DoCmd.SetWarnings False
'Now clear table "SelCruise Data"
DoCmd.OpenQuery "Clear CruiseSel Data Query", acViewNormal
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
'Now run query linking "SelCruise" which has selected Cruises and "Cruise Station" table
'to put Cruise, Station, Latitude and Longitude into table "SelCruise Data"
DoCmd.OpenQuery "CruiseSel Data Query", acViewNormal
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm ("Get Stations Make Table"
When this code is run the second form gets exactly the data from the Cruise(s) I want. If I change the Pause time to 2 seconds, it fails.
This is all run on a Pentium 600 MHz machine on Windows 2000 with the database on my local hard drive so there is no lag with using netword drives.
Is there some way to force a wait until one query is completed before the next is run, I thought Access/VBA would do this automatically i.e. wait until the actions from one line of code is completed before the next is run.
Thanks
George