Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runcode from Switchboard button

Status
Not open for further replies.

cg084

Technical User
May 3, 2002
67
GB
Hello,

I am developing a database in Access 97. Behind the times but i work for tight wallet people.

I have used the switchboard manager to create my switchboard. I have created an option in the manager to run some function. I have a function called Exports which is in the VB for the switchboard form. Yet when in the switchboard manager i enter the function name as the function name (in my case Exports()) it appears fine. Yet when you try to click on the button i get the warning message. "There was an Error executing the command!".
I need to find out where i have gone wrong.
 
I am assuming that you are using the switchboard manager to create your switchboard and that you have not created any new buttons on the switchboard to run the code you added to the Switchboard forms module.

Try moving the code to a seperate module making sure the Function (and it HAS to be a function - not a sub) is declared Public.

You then make a macro that utilises the RunCode instruction and point it to the newly made function using the expression builder.

Finally, use the switchboard manager to add an extra menu item to one of the menus and use the Run Macro command.


 
When using the Switchboard manager you have to option of running a macro or a code from one of the buttons. You also have the option to run code as well. Since my function is on the VB for the switchboard for i had not thought that i would need to declare as public since it would check there anyway. but no matter how i refer to the function it still dos not work. but i will try as you suggest.

Cheers
 
The other thing you could check is that you included the () after the function name when specifying the Function name in the Switchboard manager. I know the Macro RunCode instruction requires the parenthesis even when the Function has no agruments. The RunCode instruction on the switchboard is probably the same.
 
I used the parenthesis after the function name. Cant understand it. If i use the macro way it works fine but when i use it from the switchboard it does not.

Puzzled and annoying. Worked around it by just using the macro but it is something i would like to find out for future reference and my own satisfaction.

Cheers for your help.

 
cg084,

Were you ever able to get the RunCode() argument working from the Switchboard?

Here's what I've gotten so far in case anyone else runs into this problem.

If I enter just the name of the function - no () - for function name (i.e. Export) the code runs OK from SB. In my situation, my function requires a parameter, and I haven't been able to get it working without altering the Switchboard code.

In the 'HandleButtonClick' event, there is a Select Case statement with the Case conCmdRunCode. The statement it executes, Application.Run rs![argument] causes your function name (rs![argument]) to be interpreted as a string and then cannot be found in the module since it is looking for "nameoffunction(nameofparameter)" as the complete function name.

I took out this code and replaced it with
Eval (rs![argument])

This seems to work for me with/without a parameter, but you do have to include the () when entering the function name. (i.e Export())

Janel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top