Pheliciano
09-09-2010, 10:22 PM
I'm writing a database in Access 2007 and I've come across a bit of a problem.
I have a bunch of items in an Items table which contains a Yes/No 'Selector' field to enable the users to select which items they want to affect when performing certain actions. In using the database, the user checks the box for the items they want toaffect and then chooses an action they want to perform on those items. Once the action is complete, VBA clears all the selected fields to make sure that actions aren't performed on items by mistake.
Here's an example of the code from one of the actions:
DoCmd.RunSQL "UPDATE tblItems SET tblItems.Status = '" & strStatus(2) & "' WHERE tblItems.[Selector] = True "
DoCmd.Close acForm, "frmInspected"
DoCmd.OpenReport "rptRepair", acViewPreview, , "tblItems.[Selector] = True"
ClearSelected
Done
And here are the 'ClearSelected' and 'Done' Procedures:
Sub Done()
Dim myMessage As Byte
myMessage = MsgBox("Done", vbOKOnly + vbInformation)
End Sub
Sub ClearSelected()
DoCmd.RunSQL "UPDATE tblItems SET tblItems.Selector = False WHERE tblItems.[Selector] = True"
End Sub
This all behaves as I want it to until I perform the action on more than two items at once. The code seems to be executing too quickly, it opens the report, but before it has loaded a page for each item it has moved on to the 'ClearSelected' procedure and so obviously there are no selected items left to run the report on.
If I comment out the 'ClearSelected' line in the action code then the report opens for all of the selected items rather than just the first two.
How can I make the code wait until the report has been run on all items before going ahead with the 'ClearSelected' procedure? Bearing in mind that the action could be run on any number of items and so the report could take any amount of time to open fully.
Any ideas? Thanks!
I have a bunch of items in an Items table which contains a Yes/No 'Selector' field to enable the users to select which items they want to affect when performing certain actions. In using the database, the user checks the box for the items they want toaffect and then chooses an action they want to perform on those items. Once the action is complete, VBA clears all the selected fields to make sure that actions aren't performed on items by mistake.
Here's an example of the code from one of the actions:
DoCmd.RunSQL "UPDATE tblItems SET tblItems.Status = '" & strStatus(2) & "' WHERE tblItems.[Selector] = True "
DoCmd.Close acForm, "frmInspected"
DoCmd.OpenReport "rptRepair", acViewPreview, , "tblItems.[Selector] = True"
ClearSelected
Done
And here are the 'ClearSelected' and 'Done' Procedures:
Sub Done()
Dim myMessage As Byte
myMessage = MsgBox("Done", vbOKOnly + vbInformation)
End Sub
Sub ClearSelected()
DoCmd.RunSQL "UPDATE tblItems SET tblItems.Selector = False WHERE tblItems.[Selector] = True"
End Sub
This all behaves as I want it to until I perform the action on more than two items at once. The code seems to be executing too quickly, it opens the report, but before it has loaded a page for each item it has moved on to the 'ClearSelected' procedure and so obviously there are no selected items left to run the report on.
If I comment out the 'ClearSelected' line in the action code then the report opens for all of the selected items rather than just the first two.
How can I make the code wait until the report has been run on all items before going ahead with the 'ClearSelected' procedure? Bearing in mind that the action could be run on any number of items and so the report could take any amount of time to open fully.
Any ideas? Thanks!