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

Pause VBA Code 1

Status
Not open for further replies.

bxgti4x4

Technical User
Feb 22, 2002
167
GB
I have a Command Button that executes the following code
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:
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
 
You need to reinitiliaze Start = Timer

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PSV, that was all it took.

Best Regards
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top