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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
mark2150Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.