Can you cause the MsgBox comand yes/no to effect a result ?

JJordan

Registered User.
Local time
Today, 01:34
Joined
Jul 25, 2002
Messages
53
I am NEW at this, but I have a command button on a form that is set to

docmd.openreport("All UnReceipted Donations") acPreview

I am trying to use the MsgBox but am having trouble with formatting it and with causing it to effect a result.

I want to use a yes/no MSG pop up windows with a message next to say "Do you want to Print the report?"

If YES, I want to initiate a docmd.openreport("all unreceipted donations") acPrint -- if No, I want to do Nothing - end event (previewed reports are just left where they are.)

If they chose YES, Print, I want to have another message box pop up that says "Did the receipts print properly?"

If YES is selected, I want to run an update query that I have written to update the "Receipt_Generated" filed in the IndDonations table to YES. (so that the next time receipts are generated it will be only for the people that have no receipts)

If NO, I want it to ask Print Again or cancel? and if Print Again, start the loop over at the "Did the receipts Print Properly ?"

I do NOT want the command to cause the update query to run if the user stops the process at any point. (i.e., I only want to run it if one of the above printed correctly yes/no commands is YES)

Thus, if I put it in a string after the

DoCmd.OpenReport acPreciew
MsgBox (??????) "Do you want to Print the receipt ?" (the event needs to stop and wat for a YES or No)
If No, stop entirely (cancel event)
If Yes, initiate Print and pop up MSGBox (????) "Did the receipt print correctly ?"
If Yes, DoCmd RunQuery "update query", if no, MSGBox "Do you want to try to Print Again" (Yes or Cancel - or No) and if Yes, initiate PrintReport again and ask Printed yes/no again and

and if Cancel/No - end event.

How can I do this ? I tried creating additional Forms that ask each question with a Yes command button and a No commnd button on the forms, and set the event for the yes/no buttons, but would like to do it with the MsgBox if that is a better way to accomplish this (why have a yes/no cancel message box if it does nto cause anythig to happen)
:(
 
Last edited:
Dim Response as string

DoCmd.OpenReport "ReportName", acPreview

Response = MsgBox ("Do you want to Print the receipt ?", vbYesNo + vbQuestion

If Response = vbYes then
DoCmd.OpenReport "ReportName", acPrint
Response = MsgBox ("Did the receipt print correctly?", vbYesNo + vbQuestion

If Response = vbYes then
Docmd.Openquery"YourQueryetc"
Else
Exit Sub
End if

Else
Exit Sub
End if


Try that to get you going. If you want to enhance it further you may be able to work it out from this, if not repost and someone will help
 
The following function will basically do as you require, it will work for any report. The only problem you are going to have is calling this at a time that allows the user to preview the report and check it's correct before printing.

Public Function DoPrintRep()

If MsgBox("Do you want to print the reports?", vbYesNo) = vbYes Then
DoCmd.PrintOut
If MsgBox("Did the receipts print correctly?", vbYesNo) = vbYes Then
DoCmd.OpenQuery "Update Query"
Else
DoPrintRep
End If
End If

End Function

You can call it like below and it will prompt with the question right after the report opens. This means that if the report runs over more than one page the user will not get a chance to review the report before having to answer Yes or No.

DoCmd.OpenReport "All UnReceipted Donations", acViewPreview
DoPrintRep

Using DoEvents you could simulate a time delay to allow the user to preview the report as follows

DoCmd.OpenReport "All UnReceipted Donations", acViewPreview
For i = 1 to 100000
DoEvents
Next
DoPrintRep

1 to 100000 gives about a 40 second delay on my PC. The only problem is if the user closes the report within those 40 second the prompt still comes up even though there is no longer a report to print.
 
antomack,

DoCmd.OpenReport "All UnReceipted Donations", acViewPreview
For i = 1 to 100000
DoEvents
Next
DoPrintRep


Is there no other way to set how long preview is shown?

Maybe like
TimeStart=Now()
If Now() = TimeStart + 40 Secs Then
acViewPreview
End If

(This is not real code just an idea of how the code might flow, I don't know any Access VBA)
 
Thanks

I think it is getting close. The button did what I wanted, but you cannot actually preview the report (when the yes/no dialog pops up, all is locked until you select, so you cannot look at the reports to see if you want to print them :( (and they pulled up in Design View but print normal ? Where did that come from) :)

Edit: I put in the Delay from above and it gives you time to review the receipts before executing the Msg. For some reason, though, the reports both switch to Design View after you go past the first message box "Do you want to print a receipts"

Here is what I have in place: (the first Query creates a TempReceiptTable used to generate the two reports)


DoCmd.OpenQuery ("Generate Receipts From Table")
DoCmd.OpenReport ("Labels for Receipts Generated"), acViewPreview
DoCmd.OpenReport ("Donation Receipts from TempReceiptTable"), acViewPreview

For i = 1 To 10000
DoEvents
Next

Dim Response As String

Response = MsgBox("Do you want to Print the receipts ?", vbYesNo + vbQuestion)

If Response = vbYes Then
DoCmd.OpenReport ("Donation Receipts from TempReceiptTable"), acPrint

Response = MsgBox("Did the receipt print correctly?", vbYesNo + vbQuestion)

If Response = vbYes Then
Response = MsgBox("Do you want to print Mailing Labels ?", vbYesNo + vbQuestion)
If Response = vbYes Then

DoCmd.OpenReport ("Labels for Receipts Generated"), acViewPrint

Response = MsgBox("Did the Lables Print Correclty ?", vbYesNo + vbQuestion)
If Response = vbYes Then
DoCmd.OpenQuery "Update Receipt Generated Field to Yes"

Else
Exit Sub
End If

Else
Exit Sub
End If

Else
Exit Sub
End If

Else
Exit Sub
End If

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom