Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2004, 07:54 PM
Authorized User
 
Join Date: Aug 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default Set Warnings

I have used the code DoCmd.SetWarnings False and DoCmd.SetWarnings True to turn off errors if some one clicks cancel on a command button. The main concern I have is when I have this code in a command button and when I click cancel, it gives a VBA error window that says the user has canceled the operation. Is there a way to turn off other messages as well with VBA code or is SetWarnings the only way?

 
Old October 26th, 2004, 09:18 PM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SetWarnings False won't do it. You need to trap the 2501 Err code (cancel) in the code that initiated the action. Typically, you're trying to open a form or report, and the Open event cancels the open. Use On Error and test for the code in your error code.


John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
 
Old October 27th, 2004, 12:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

That second warning message is a VBA run-time warning telling you that your code is failing. That's something you DON'T want to turn off, but as JLovell suggested, you can trap the error and either create a more meaningful error message or not display anything.

I don't recommend the latter because if something is really wrong, you want to know it or your form is unreliable and may bomb out.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old October 27th, 2004, 10:08 PM
Authorized User
 
Join Date: Aug 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the help. I was able to trap the error so I think I have that problem resolved. I just have a question regarding the process of trapping errors in general. I copied some code from a different command button and tried using that. It worked for the most part until VBA saw the following line of code:

(Copy Source)
Private Sub cmdCloseReports_Click()
    On Error GoTo Err_cmdCloseReports_Click
    DoCmd.Close
Exit_cmdCloseReports_Click:
    Exit Sub
Err_cmdCloseReports_Click:
    MsgBox Err.Description
    Resume Exit_cmdCloseReports_Click
End Sub


(Copy Destination)
Private Sub cmdDisplayReport_Click()
    On Error GoTo Err_cmdDisplayReportCancel_Click
    'Open the selected report in Datasheet view.
    DoCmd.SetWarnings False
    DoCmd.OpenReport Me.lboxReportList, acViewPreview
    DoCmd.SetWarnings True
'Exit_cmdDisplayReportCancel_Click
    Exit Sub

Err_cmdDisplayReportCancel_Click:
    MsgBox Err.Description
    'Resume Exit_cmdDisplayReportCancel_Click

End Sub

When I copied the error trap(I guess that is what you call it) from cmdCloseReports and after I changed the code to reflect the new command button, it didn't like the Resume command I have formatted in bold above and it gave a run time error.

As you can see I commented the code:
 'Resume Exit_cmdDisplayReportCancel_Click for cmdDisplayReport to see if that would eliminate the run time error(and it did). I just want to know what the purpose of the Resume command was in the first place and what was causing the run time error. Please let me know if my question makes sense. I placed the code for the two command buttons to better explain what I was getting at.

Thanks again?

Chad
 
Old October 27th, 2004, 11:12 PM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need a colon after every label:

Exit_cmdDisplayReportCancel_Click:


John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"





Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Backgound / Color warnings socoolbrewster CSS Cascading Style Sheets 3 January 4th, 2007 08:15 AM
Warnings under ASP.NET 2.0 dw BOOK: Professional Crystal Reports for VS.NET 0 March 8th, 2006 03:46 PM
How to view warnings IronStar MySQL 1 May 1st, 2005 10:46 PM
how to off php notices and warnings knight Beginning PHP 2 February 3rd, 2005 03:34 PM
Help Sesssion Warnings! Empier4552 Beginning PHP 1 July 8th, 2003 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.