Report doesn't exit

B

Bill

I have a report opened via a DoCmd.OpenReport in
acViewPreview mode with arguments. In OnOpen code
sheet I have:

******************************begin
code**************************************************************
Private Sub Report_Open(Cancel As Integer)
Dim Arg() As String
Dim PicFile As String
Const ImageName = "ProgOutsideFront.jpg"

'========================================================================================'
' Openargs contains two arguments separated by a semicolon. The first is the
folder name
' of the folder containing the jpg file of the front cover image. The second
argument is
' the formated date of the next performance of the form: month day, year
'========================================================================================'
Arg = Split(OpenArgs, ";") ' Break OpenArgs into its
two components
PicFile = "C:\GAP\" & Arg(0) & "\" & ImageName ' Format fully qualified
image file name


If Dir(PicFile) = ImageName Then ' Check to see if file
exists.
Me.FrontImage.Picture = PicFile ' Assign that to image
control for linking
Me.LBL_NextPerf.Caption = Arg(1) ' Next perf date also on
back of booklet
Arg = Split(Me.LBL_NextPerf.Caption, " ") ' Strip off the month name
Me.LBLConcertFor.Caption = "Concert For " & Arg(0) ' Month also
appears on back
Else
MsgBox "The image file " & PicFile & " does not exist."
Exit Sub
End If

End Sub
***************************************end
code******************************************************

In my testing, I purposely ran a case where the required file
was missing. I did in fact get the MsgBox message, but
the report previewed anyway, rather than exit the report.
Is there something peculiar about the code running in
preview mode? I.e., the report continued minus the
image that would otherwise be included in the report.

Bill
 
L

Larry Linson

Help me understand: what in your code did you think you did to stop the
report from running? Exiting the Open event's procedure doesn't do it.

Try setting the Cancel argument to True prior to Exit Sub.

Larry Linson
Microsoft Access MVP
 
B

Bill

Obviously, I wasn't thinking "exit sub" but rather thinking
abort the open. Anyway, "Cancel = True" in fact cancelled
the report. Now, I would like to suppress the Access
warning message that is issued when the report is cancelled.
How do I accomplish that little detail?

Thanks,
Bill
 
S

SA

Bill:

The error that is generated by a cancel call is error 2501. So in what
ever function or sub you call that opens the report add an error handler
like:

Public Sub ShowMyReport ()
On error goto Err Handler
'-----your code here------

ExitProc:
Exit Sub
ErrHandler:
If Err = 2501 Then
Resume ExitProc
Else
MsgBox "Error: " & Err.Number & " " & Err.Description
Resume ExitProc
End If
End Sub
 
B

Bill

The error condition was not raised per your code
suggestion below:

If Dir(PicFile) = ImageName Then ' Check to see if file
exists.
Me.FrontImage.Picture = PicFile ' Assign that to label
control
Me.LBL_NextPerf.Caption = Arg(1) ' Next perf date also on
back of booklet
Arg = Split(Me.LBL_NextPerf.Caption, " ") ' Strip off the month name
Me.LBLConcertFor.Caption = "Concert For " & Arg(0) ' Month also
appears on back
Else
MsgBox "The image file " & PicFile & " does not exist."
On Error GoTo ErrHandler ' The cancel should raise
error 2501
Cancel = True

ExitProc: Exit Sub ' Okay, now we can leave

End If

ErrHandler:
If Err = 2501 Then
MsgBox Err.Number <<<<<<<<<<<<<<<<<<<Didn't execute
Resume ExitProc
Else
MsgBox "Error: " & Err.Number & " " & Err.Description
Resume ExitProc
End If
End Sub
 
L

Larry Linson

I found that I, too, still got the error message box despite having the
error handling. Dirk Goldgar, an Access MVP colleague, asked me if I had
"Break on all errors." turned on. I looked in the Options in the Visual
Basic Editor window, and, yes, I did have "Break on all errors" checked. I
changed that setting to "Break on unhandled errors", ran the report again,
and no error.

So, that is a setting for you to check.

I never got the error when I clicked the report directly to open it... it
just never opened. My report was a copy of a simple Report into which I had
just inserted "Cancel = True" and the error handling in the Open event.

Larry Linson
Microsoft Access MVP
 
B

Bill

Larry,
That explains it. I'd just upgraded my system to 2003 and "Break on all
errors" must be the default on new installs.

While I have you attention, would you have a look at my "Vertical Text"
post from earlier. I cannot get the orientation controls to function as I
was given to understand they would..... I didn't have those controls at
all in O2K.

Thanks,
Bill
 
L

Larry Linson

While I have you attention, would
you have a look at my "Vertical Text"
post from earlier. I cannot get the
orientation controls to function as I
was given to understand they would.....
I didn't have those controls at
all in O2K.

That's a feature I have not used, so I think I'd best leave it to someone
else. It's an interesting thought to learn something about it, but learning
on the fly to answer a post may be "pushing things" a bit.

Larry Linson
Microsoft Access MVP
 
B

Bill

Thanks anyway for your consideration. I've since had
a few exchanges with Allen Browne in Australia and
he put me on to something Lebans had written. I've
been in contact with Stephen and he is trying to
understand why I'm experiencing some problems in
the use of his fRotateRunTime.

Thanks again,
Bill Stanton
 

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