I have a Command Button that executes the following code
The first timer function works well and allows me to view the three pages of the report. When the code resumes, the message box appears and, if I press the "Yes" button, indicating that there are duplicates, the next query runs and presents the report again. At this point I want the code to pause again so that I can inspect all three pages of the report but, although I have used the same timer function, the code does not pause and the message box appears immediately.
If there are still duplicates after running "QryPresident_DeleteDuplicates(W)", the "Yes" button in the message box is pressed and the code repeats itself using a second, third and fourth query. I need to be able to pause between each operation to check all three pages of the report for duplicates.
I would be grateful if someone can tell me where I am going wrong
Best Regards
John
Code:
Private Sub RptPresident_Click()
On Error GoTo Err_RptPresident_Click
Dim stDocName As String
Msg = "Are there any duplicates?"
Style = vbYesNo + vbDefaultButton1
Title = "DUPLICATE RESULTS"
Dim PauseTime, Start
PauseTime = 6
Start = Timer
stDocName = "RptPresident1"
DoCmd.DeleteObject acTable, "TblPresident"
DoCmd.SetWarnings False
DoCmd.OpenQuery "QryPresident_MT", acViewNormal, acReadOnly
DoCmd.OpenReport stDocName, acPreview
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
'Check for Duplicates
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
DoCmd.Close
DoCmd.OpenQuery "QryPresident_DeleteDuplicates(W)", , acEdit
DoCmd.OpenReport stDocName, acPreview
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
Else
DoCmd.Close
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom100
DoCmd.SetWarnings True
Exit Sub
End If
'Continues:
If there are still duplicates after running "QryPresident_DeleteDuplicates(W)", the "Yes" button in the message box is pressed and the code repeats itself using a second, third and fourth query. I need to be able to pause between each operation to check all three pages of the report for duplicates.
I would be grateful if someone can tell me where I am going wrong
Best Regards
John