Passing a Function Argument through the Switchboard

G

Guest

I've got a database with similar reports with subtle name variations (e.g.
GN1rpt, AI1rpt, WI1rpt, VA1rpt, VA2rpt, WI2rpt, etc) and would like a single
function I could call from a button on the switchboard that gets passed the
name of the report (1rpt or 2rpt in my example above).

My function resembles:

Public Function PreviewReport(strReportName As String)

What is the syntax in the Switchboard Manager to pass an argument to a
Function?

TIA,

Ladd
 
S

storrboy

I've got a database with similar reports with subtle name variations (e.g.
GN1rpt, AI1rpt, WI1rpt, VA1rpt, VA2rpt, WI2rpt, etc) and would like a single
function I could call from a button on the switchboard that gets passed the
name of the report (1rpt or 2rpt in my example above).

My function resembles:

Public Function PreviewReport(strReportName As String)

What is the syntax in the Switchboard Manager to pass an argument to a
Function?

TIA,

Ladd


Whenever you call a function (or sub) arguments are passed following
the name of the procedure. Brackets are used when you expect a return
value from the function.

example
TestMe 'Calls a sub or function with no arguments
someVar = TestMe(arg1, arg2) 'calls a function and returns value to
somevar.

In your example you would use - PreviewReport "ReportName" -since you
are not expecting a return value.
 
G

Guest

If your function is

Function PreviewReport(strReportName As String)
Docmd.OpenReport strReportName
End Function

To call the function you can use 2 ways
1.
PreviewReport "GN1rpt"

2.
Dim x
x = PreviewReport ("GN1rpt")
 
G

Guest

I've tried that syntax and get "There was an error executing the command."
When I look at the table "Switchboard," the name of the function to run is
(in itself) an argument.

Item# ItemText Command Argument
5 Test 8 PreviewReport "rptMemberList"

I must still be missing something.

TIA,

Ladd
 
S

storrboy

I've tried that syntax and get "There was an error executing the command."
When I look at the table "Switchboard," the name of the function to run is
(in itself) an argument.

Item# ItemText Command Argument
5 Test 8 PreviewReport "rptMemberList"

I must still be missing something.

If you are talking about the box beside the OnClick Event in the
properties box, that is not an argument. It is the name and argument
of the function to call when the button is clicked. Not sure but I
think it needs to be preceeded by an =.

rptMemberList is not one of the "...1rpt or 2rpt in my example
above..."
Does this report exist?
 
G

Guest

storrboy,

Thank you for your persistence. I don't think I am explaining my situation
properly. Let me see if this sheds some light on my problem:

I'm using the built-in Switchboard Manager functionality (Tools -- Database
Utilities -- Switchboard Manager) to provide a menuing system that could be
modified by the user should they wish to do so.

I have instructed the Switchboard Manager to run the function PreviewReport
(as hopefully shown below):

<img src="http://www.dbqphlockers.org/images/AccessSwitchboard.png"
width="486" height="118" />

The Switchboard Manager gets its data from a table called "Switchboard
Items" and in this table, command "8" or "Run Code" is being called by
Access. This command is being passed an argument which is the name of the
function:

<img src="http://www.dbqphlockers.org/images/AccessSwitchboardTable.png"
width="539" height="112" />

Since my function is being passed as an argument, I'm tyring to figure out
the syntax that allows my function to get its argument.

I hope this clarifies things a bit. Thanks again for your persistance.

Ladd
 
S

storrboy

storrboy,

Thank you for your persistence. I don't think I am explaining my situation
properly. Let me see if this sheds some light on my problem:

I'm using the built-in Switchboard Manager functionality (Tools -- Database
Utilities -- Switchboard Manager) to provide a menuing system that could be
modified by the user should they wish to do so.

I have instructed the Switchboard Manager to run the function PreviewReport
(as hopefully shown below):

<img src="http://www.dbqphlockers.org/images/AccessSwitchboard.png"
width="486" height="118" />

The Switchboard Manager gets its data from a table called "Switchboard
Items" and in this table, command "8" or "Run Code" is being called by
Access. This command is being passed an argument which is the name of the
function:

<img src="http://www.dbqphlockers.org/images/AccessSwitchboardTable.png"
width="539" height="112" />

Since my function is being passed as an argument, I'm tyring to figure out
the syntax that allows my function to get its argument.

I hope this clarifies things a bit. Thanks again for your persistance.

Ladd


First time I've looked at what the Switchboard form does. I've never
used except in someone else's app.

I know what you can do, but it will take a little bit of modifying. We
need to change the table the switchboard is based on and modify the
HandleButtonClick function.

BACKUP DATABASE BEFORE YOU START! (Too loud? Sorry)

Modify table "Switchboard Items":
- Open table
- Change the number in the Command field from 8 to 9 (we're making a
custom command)
- Change the Argument field to PreviewReport('rptMemberList')
Note the brackets and single quotes
- Close the table

Modify Swithcboard Form:
- Open form in design view
- Choose View>Code from the main menu
- At the top right of the code window is a drop-down that probably
says (Declarations). Select HandleButtonClick to take to the function
we're going to change.
- Near the top of this function there are some lines that look like
the following...

Const conCmdRunMacro = 7
Const conCmdRunCode = 8

Below these add this line: Const conCustomReport = 9

- Scroll down a little ways until you find a section that looks like
this
' Run code.
Case conCmdRunCode
Application.Run rst![Argument]

Add the following below that section
'Run code with arguments
Case conCustomReport
Eval rst![Argument]

Save the changes to the form, close it and try it out. Let me know if
it doesn't work.
 
J

John Nurick

Hi Ladd,

Unfortunately you can't do it that way. The standard switchboard code
uses Application.Run to run code, and passes whatever command you've
specified as a single argument. So if you enter this as the command
PreviewReport MyReport
the Swtichboard Manager executes
Application.Run "PreviewReport MyReport"

But as Help for Application.Run shows, it takes multiple arguments. The
first is the name of the procedure, and the remainder are passed to the
procedure, so what's needed is:
Application.Run "PreviewReport", "MyReport"

How about one of the following:
1) Create a bundle of wrapper functions, one per report, each calling
PreviewReport with the right argument(s), and set up one switchboard
item for each.

2) Revise PreviewReport so it puts up a form with a list of reports for
the user to select from, so can be run from a single switchboard button.
 
S

storrboy

That's why I added the Case 9 with the Eval function. It will then
accept the argument field the way Gladdys65 had it, as long as they
change the number in the table from 8 to 9.
 
G

Guest

That got it! Thank you for your assistance. I had to make a few subtle changes:

Rather than:
Const conCustomReport = 9

I needed to use:
Const conCustomReport = 10

Rather than:
Eval rst![Argument]

I needed to use:
Eval rs![Argument]

However, once implemented the argument was accepted via the Switchboard. I
should mention the "Custom Report" option won't show up in the "Edit
Switchboard" dialog box shown at
http://www.dbqphlockers.org/images/AccessSwitchboard.png but I don't think
that is a critical issue right now. Thank you again for your assistance!

Ladd

First time I've looked at what the Switchboard form does. I've never
used except in someone else's app.

I know what you can do, but it will take a little bit of modifying. We
need to change the table the switchboard is based on and modify the
HandleButtonClick function.

BACKUP DATABASE BEFORE YOU START! (Too loud? Sorry)

Modify table "Switchboard Items":
- Open table
- Change the number in the Command field from 8 to 9 (we're making a
custom command)
- Change the Argument field to PreviewReport('rptMemberList')
Note the brackets and single quotes
- Close the table

Modify Swithcboard Form:
- Open form in design view
- Choose View>Code from the main menu
- At the top right of the code window is a drop-down that probably
says (Declarations). Select HandleButtonClick to take to the function
we're going to change.
- Near the top of this function there are some lines that look like
the following...

Const conCmdRunMacro = 7
Const conCmdRunCode = 8

Below these add this line: Const conCustomReport = 9

- Scroll down a little ways until you find a section that looks like
this
' Run code.
Case conCmdRunCode
Application.Run rst![Argument]

Add the following below that section
'Run code with arguments
Case conCustomReport
Eval rst![Argument]

Save the changes to the form, close it and try it out. Let me know if
it doesn't work.
 
S

storrboy

That got it! Thank you for your assistance. I had to make a few subtle changes:

Rather than:
Const conCustomReport = 9

I needed to use:
Const conCustomReport = 10

Rather than:
Eval rst![Argument]

I needed to use:
Eval rs![Argument]

However, once implemented the argument was accepted via the Switchboard. I
should mention the "Custom Report" option won't show up in the "Edit
Switchboard" dialog box shown athttp://www.dbqphlockers.org/images/AccessSwitchboard.pngbut I don't think
that is a critical issue right now. Thank you again for your assistance!

Ladd




First time I've looked at what the Switchboard form does. I've never
used except in someone else's app.
I know what you can do, but it will take a little bit of modifying. We
need to change the table the switchboard is based on and modify the
HandleButtonClick function.
BACKUP DATABASE BEFORE YOU START! (Too loud? Sorry)
Modify table "Switchboard Items":
- Open table
- Change the number in the Command field from 8 to 9 (we're making a
custom command)
- Change the Argument field to PreviewReport('rptMemberList')
Note the brackets and single quotes
- Close the table
Modify Swithcboard Form:
- Open form in design view
- Choose View>Code from the main menu
- At the top right of the code window is a drop-down that probably
says (Declarations). Select HandleButtonClick to take to the function
we're going to change.
- Near the top of this function there are some lines that look like
the following...
Const conCmdRunMacro = 7
Const conCmdRunCode = 8
Below these add this line: Const conCustomReport = 9
- Scroll down a little ways until you find a section that looks like
this
' Run code.
Case conCmdRunCode
Application.Run rst![Argument]
Add the following below that section
'Run code with arguments
Case conCustomReport
Eval rst![Argument]
Save the changes to the form, close it and try it out. Let me know if
it doesn't work.

Glad you got it working.
 
Joined
Sep 24, 2012
Messages
1
Reaction score
0
This may be a little obvious and may or may not address the issue - but if you are pressed for time and don't want to test out all of the enhancements to switchboard proposed in this thread, you could simply include functions that don't need arguments. If you think about it - it is usually six of one half a dozen of another whether you need to do this inside a switchboard button ref:

myfunction(arg1)

or whether you simply add function calls in your vb module and then use them in your buttons like this:

myfunction(arg1)
specificFunc1 { myfunction(arg1) }
specificFun2 { myfunction(arg2) }

and then just call specificFunc into the button. It's a bit more typing but it works cleanly and still permits you to set up most of your code in a re-usable module and then just change the "reference functions" that will be used in button code.
 

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