stop code while report open

J

Josh

Everything I've found on google reference subject turns out to be not what I
need (if I even know what I need), or I don't quite understand it.

I have a cmd button on a form, which opens a report (rptStatement). Next, AFTER
statements are printed, I insert NOW() into a table, thereby giving me my next
"previous balance" date next month.

If user opens report (preview) and then for whatever reason (printer out of ink,
who knows why) doesn't print the statements, then I do NOT want NOW() inserted.
Even if I didn't open in preview, just printed, user might still have had paper
jam or whatever, so I want to wait until print job is through..maybe 5 minutes?

Problem is, the report opens in preview mode, but my msgbox "did they print ok
and do you want to continue" immediatly opens over the top of the report, and
user cannot get to the preview to print or look at them, unless they answer the
msgbox and proceed to insert Now() anyways.

How can I stop/pause code execution until after the report has printed?

I've looked at Loop, but I must not understand it enough, it is still preventing
me from looking/printing report, because of hourglass (cpu doing something for
sure).

Thanks, Josh
 
A

Allen Browne

Josh, how about moving your MsgBox question and code into the Close event of
the report?
 
T

tina

since you're opening the report in Preview, how about putting the code with
the message box and the "Now()" option in the report's Close event, instead
of including it in the code that opens the report?

hth
 
G

Guest

It seems a bit limiting in design, for the exact same reasons you outline. If
something goes wrong or you want to change the date, then you have a problem
and have to get an administrator to change the date.

Firstly, why not have a visible date on your form, and the date manually
input. (or some other way rather than the way you current have).

Secondly if you insist on designing it this way, which I would not
recommend, you could put some code in the on_close event of your report.

That is, have a Yes/No message box open up in the on close of the report
asking if the report printed Ok and the staff member has done what they are
supposed to with the report (eg: filed it), and then if the user clicks yes,
then insert Now(), else do not insert now and bring up the print preview
again.


Something like:


Private Sub Report_Close()

On Error GoTo ErrorPoint

Dim strReportName As String
Dim strCriteria As String
Dim strMessageResponse As String

strMessageResponse = MsgBox(" Did the report print Ok. Note: If you click
Yes, this will insert todays date ..... ", vbYesNo, "Report Print Status")

strReportName = “rptStatementâ€

If strMessageResponse = vbYes Then

'Insert your code update field

Else
'Code to bring up the print preview again with linking criteria to your
current form

strMessageResponse = MsgBox(" Would you like to print again?", vbYesNo,
"Reprint?")

If strMessageResponse = vbYes Then

'code to print

DoCmd.OpenReport strReportName, acViewNormal, , strCriteria

MsgBox(" Report Printed", "Report Printed")

End If

End If


ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " _
& Err.Description, vbExclamation, _
"Unexpected Error"
Resume ExitPoint




End Sub


' Code obviously not tested
' Hope that this helps
 
J

Josh

Thanks Allen and Tina.......

I knew that was an option, but I was bound and determined to do it "my way".
Finally gave up banging my head against the brick wall, and did as both of you
suggested, which works fine.

Now I don't even remember why I discarded that idea in the first place....sigh

Thanks, Josh
 
J

Josh

Hmmmm, food for thought. I've gone ahead and put the code in the onClose event
of the report, so it works ok now. As for having a date on the form that the
user can change, my thinking was "who knows what they'll put in if I let them",
so thought better to just handle it this way.

But, that does bring up a point that I had vaguely thought of, that I need a
method of allowing user to change that date (or delete) if something went
haywire.

Thanks
 
G

Guest

You could always have some validation code on the date field if you put it on
the form. Something like in the On_Update event of the field on your form,
me.datefield is >= Now()-7 days". That is, is within one week of today. Or
better yet, rather than using Now(), as this may cause problems in the future
if you want to update the field to a correct date and it is not within one
week of now, within one week of the end of a period using the dates already
on your form somehow.

hth
 
G

Guest

Just had a thought or two.

After "yes printed OK, then insert the date into the visible field on your
form so that the user does not have to put in the date. You could make the
field a non-tab stop feild so the user doesn't need to tab past it.

You could also make it enable = false, and have a small command button next
to it that made it enabled = true when clicked, (or double clicked the field
itself) so that 99% of the time it was greyed out "not enabled" uintil the
user deliberately clicked the button (or double clicked the field) so that
they can change the date.

Just an idea.
 
A

Allen Browne

Good on ya, Josh.

Once you learn to trust the events to fire so that all you have to do is
respond to them, it simplifies your whole life as a developer. "-)
 

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