report

I use VB6 to print a report directly from access 97,. it works ok to print, but if i choose cancel button in the dialog box (parameter query box to enter date or id...etc) this produces a run time error 2501 and then exits
the program.  how can i solve this please from BV6.
sml41Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mark2150Connect With a Mentor Commented:
Insert an:

ON ERROR RESUME NEXT

statement as the first line in your sub. Any error will be caught and ignored (the requested function will still fail) but you .EXE should be able to continue to fly.

If you need to know wether the function was successful try:

Private Sub bookingBetweenTwodates_Click()
ON ERROR GOTO TRAP
Set Access = GetObject(App.Path & "\MyDb.mdb")
Access.DoCmd.OpenReport ("MyAccessReport")

Set Access = Nothing
EXIT SUB
' ==========
' Here on error
TRAP:
RESUME TRAP1  'Clear error state
'
TRAP1:
MSGBOX "An Error Occurred!"
'
End Sub
0
 
mark2150Commented:
You need to have the CancelError set to true and an ON ERROR statement in your code to run when [Cancel] is true. This is correct operation for this control.

M
0
 
sml41Author Commented:
hi,
this is my code, i experemented as u suggested, i could not succeed, can u tell me where i check for the error please in my code.

thanks
Private Sub bookingBetweenTwodates_Click()
Set Access = GetObject(App.Path & "\MyDb.mdb")
Access.DoCmd.OpenReport ("MyAccessReport")

Set Access = Nothing

End Sub
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sml41Author Commented:
thanks I visited your website, it's cool.
0
 
mark2150Commented:
Glad you liked it. Did you have your speakers on when you visited? :-)

M
0
 
sml41Author Commented:
yes i did, & i agree with you
0
All Courses

From novice to tech pro — start learning today.