Switchboard code

G

Guest

I added code to the switchboard so I could open queries, and that works
great. Got the info from
http://www.accessmvp.com/JConrad/accessjunkie/switchboardfaq.html#query

My problem is that if I cancel the input query, I get the msg: "There was
an error executing the command." In the switchboard code:

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

How can I fix this so I don't get that err msg?
 
F

fredg

I added code to the switchboard so I could open queries, and that works
great. Got the info from
http://www.accessmvp.com/JConrad/accessjunkie/switchboardfaq.html#query

My problem is that if I cancel the input query, I get the msg: "There was
an error executing the command." In the switchboard code:

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

How can I fix this so I don't get that err msg?

One of the difficulties of using the built-in Access switchboard is
that it is user unfriendly and not very functional.

You need to trap the error 2501 in the sub routine's error handler.

If Err = 2501 then
Resume Exit Sub
Else
....... Whatever other error handling you need
Resume somewhere?
End If


I don't know where or how you added the Open Query to the code, so you
may have to add an additional error handler and use that to trap the
error.

On Error GoTo Err_Handler2
DoCmd.OpenQuery "QueryName"

Exit_Sub:
Exit Sub
Err_Handler2:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

Or you might be able to simply add the
If Err = 2501 then
line to the existing error handler.

A better solution would be to scrap the switchboard and create your
own, using an unbound form with command buttons. If you use the
Command button wizard to add the buttons, Access will even write most
of the code for you. You will have more control over the switchboard
appearance, are not limited to 8 buttons, and maintenance will be
simpler.
 
G

Guest

Thanks so much for your reply :)
First I defined the command to open the query as: "Const conCmdOpenQuery =
10" which I added to the list of other constants listed. Then I added:
' Open a Query
Case conCmdOpenQuery
DoCmd.OpenQuery rs![Argument]

to the rs! SELECT CASE and changed the #'s in the switchboard table
accordingly. In the switchboard code, conErrDoCmdCancelled was defined:
"Const conErrDoCmdCancelled = 2501"

I just can't figure out why it doesn't "resume next" with the input queries,
but it will with reports, eventhough they too ask for input b/c they are
based on those very same queries! Is there another IF statement I can add
(maybe within the err handling IF stmt) that will avoid this err msg? Or
will that just give me more trouble than it's worth??

I hope I have explained this well enough. If not, just ask and I will try
to clarify. Thanks!
 
G

Guest

You are a genius! :) Thanks so much that worked great. How did you know
which err code to put in?

Jeff Conrad said:
Change this line:
If (Err = conErrDoCmdCancelled) Then

to:
If (Err = conErrDoCmdCancelled) Or Err.Number = 3270 Then

That should fix it.

--
Jeff Conrad - Access Junkie - MVP Alumni
SDET - XAS Services - Microsoft Corporation

Co-author - Microsoft Office Access 2007 Inside Out
Presenter - Microsoft Access 2007 Essentials
http://www.accessmvp.com/JConrad/accessjunkie.html
Access 2007 Info: http://www.AccessJunkie.com

----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.mspx
----------

in message:
Thanks so much for your reply :)
First I defined the command to open the query as: "Const conCmdOpenQuery
=
10" which I added to the list of other constants listed. Then I added:
' Open a Query
Case conCmdOpenQuery
DoCmd.OpenQuery rs![Argument]

to the rs! SELECT CASE and changed the #'s in the switchboard table
accordingly. In the switchboard code, conErrDoCmdCancelled was defined:
"Const conErrDoCmdCancelled = 2501"

I just can't figure out why it doesn't "resume next" with the input
queries,
but it will with reports, eventhough they too ask for input b/c they are
based on those very same queries! Is there another IF statement I can add
(maybe within the err handling IF stmt) that will avoid this err msg? Or
will that just give me more trouble than it's worth??

I hope I have explained this well enough. If not, just ask and I will try
to clarify. Thanks!
 
J

Jeff Conrad [MSFT]

Genius?
No, but thanks for the compliment.
:)

I just added this:
Msgbox Err.Number

before..
MsgBox "There was an error executing the command.", vbCritical

The error number then showed up in the Message Box.

--
Jeff Conrad - Access Junkie - MVP Alumni
SDET - XAS Services - Microsoft Corporation

Co-author - Microsoft Office Access 2007 Inside Out
Presenter - Microsoft Access 2007 Essentials
http://www.accessmvp.com/JConrad/accessjunkie.html
Access 2007 Info: http://www.AccessJunkie.com
 
G

Guest

Excellent :) Thanks again for all your help!

Jeff Conrad said:
Genius?
No, but thanks for the compliment.
:)

I just added this:
Msgbox Err.Number

before..
MsgBox "There was an error executing the command.", vbCritical

The error number then showed up in the Message Box.

--
Jeff Conrad - Access Junkie - MVP Alumni
SDET - XAS Services - Microsoft Corporation

Co-author - Microsoft Office Access 2007 Inside Out
Presenter - Microsoft Access 2007 Essentials
http://www.accessmvp.com/JConrad/accessjunkie.html
Access 2007 Info: http://www.AccessJunkie.com

----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.mspx
 

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