User intervention in BeforeUpdate

G

Guest

I often insert If MsgBox into the BeforeUpdate of various controls to ask for
a user decision about whether to continue or cancel. In one case, I need to
pop up a report so that the user can make his decision based on the content
of the report. I got this far:

If <Conditions> Then
If MsgBox("Review report?", vbExclamation + vbYesNo) = vbYes Then
DoCmd.OpenReport "<ReportName>", acViewPreview
If MsgBox("Cancel entry?", vbExclamation + vbYesNo) = vbYes Then
ShippingID.Undo
Cancel = True
End if
End If
End If

When the report opens, execution continues on to the next MsgBox, and the
user cannot review (zoom, change pages) the report until AFTER answering the
next MsgBox. How can I let the user see/zoom the report before popping up the
next MsgBox? Can I embed a control on the report itself?
 
A

Allen Browne

You need the event to complete so the user can go on to other things, so use
the AfterUpdate event of the control.

You can't cancel that event, but you can set the Value of the control back
to the OldValue if it's not acceptable. For example, you might put that code
(and MsgBox) into the Close event of the report.
 
J

John Spencer (MVP)

If you need to open the report and view it and then close the report, you can
insert a code loop to check if the report is open and if it isn't then advance
to the next step in your procedure. This would mean that the users would have
to close the report to continue on.

Something like the following in recent (2000? and later) versions of Access:

While CurrentProject.AllReports("MyReport").IsLoaded = True
DoEvents
Wend



I don't have any code that does this on this computer, but you can probably use
Google to locate a relevant piece of code.
 
G

Guest

The problem is not where the event fires, but how to pause execution on the
form while the report is open so that the If MsgBox("Cancel entry?"...) does
not pop up until after the user has an opportunity to review the report
brought up by the the first If MsgBox. This is true even if I put the first
If MsgBox in the BeforeUpdate and the second one in AfterUpdate because there
is nothing intervening to halt execution while the form is open.

I tried both While/Wend & Do While/Loop, but both of these prevented the
report from being displayed properly. I cannot use the form timer because it
is tied up with other processes.

All I want to do is interactively enable the user to cancel input based on
review of the report & leave the focus on the current control if he chooses
to cancel. For now, I simply moved the code to the AfterUpdate, disabled the
second message and let the user Shift-Tab back to change his entry if he
wants to cancel.
 
M

Marshall Barton

Brian said:
I often insert If MsgBox into the BeforeUpdate of various controls to ask for
a user decision about whether to continue or cancel. In one case, I need to
pop up a report so that the user can make his decision based on the content
of the report. I got this far:

If <Conditions> Then
If MsgBox("Review report?", vbExclamation + vbYesNo) = vbYes Then
DoCmd.OpenReport "<ReportName>", acViewPreview
If MsgBox("Cancel entry?", vbExclamation + vbYesNo) = vbYes Then
ShippingID.Undo
Cancel = True
End if
End If
End If

When the report opens, execution continues on to the next MsgBox, and the
user cannot review (zoom, change pages) the report until AFTER answering the
next MsgBox. How can I let the user see/zoom the report before popping up the
next MsgBox? Can I embed a control on the report itself?


If you're using AXP or later, you could open the report with
WindowMode = acDialog.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top