run VBA from switchboard

sambucaman

Registered User.
Local time
Today, 14:26
Joined
May 6, 2010
Messages
41
Hi all

I have the following bit of code

Code:
Private Sub Command6_Click()
Dim lngRecordCount As Long
lngRecordCount = DCount("*", "Customers")
lngRecordCount1 = DCount("*", "Stores")

MsgBox "There are " & lngRecordCount & " customers and " & lngRecordCount1 & " stores in the Starlight Database."


End Sub

Which id like to run from a switchboard button. Any ideas how id go about this?

Thanks
 
My first piece of advice would be to create your own "switchboard" form with command buttons that you code yourself to do what you want. The built in Access Switchboard is a classic case of completely over complicating what is a relatively simple task.

That being said, if you're committed to using the Access switchboard, you'll need to do a little digging. When you create a switchboard, the wizard creates a Switchboard Items table that contains info about the buttons on the switchboard and argument values that determine what happens when you click the button. It also creates some (over complicated) code in the module for your switchboard form. In this code module there will be a function -

Private Function HandleButtonClick(intBtn As Integer)

or something similar. In this function there will be a Select Case statement -

Select Case rs![Command]

which retrieves your buttons value form the [Command] field in the table and then based on that value determines what the button does. You'll need to figure out which "Case" applies to your button and add your code to that Case argument inside the Select Case statement.

Like I said, I think you'll find it easier in the long run to manage and modify a switchboard form that you create yourself.
 

Users who are viewing this thread

Back
Top Bottom