Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

Use VBA to open a specific Switchboard Page

Hello Experts.

I'm wondering how can i use vba to open a specific switchboard page.

For example, i have 2 switchboard pages (main and admin).  on my main page i have an option "Admin Login" when clicked a dialog form opens prompting the user for password, while the main switchboard is still open.

in my dialog form i have:

If me.txtPassword <> "password" Then
   MsgBox "try again"
Else
    'code to switch stwchboard page
   DoCmd.Close acForm, "frmAdmin"
End If

can anyone help me out please?

thank you.
Avatar of rockiroads
rockiroads
Flag of United States of America image

If you created the switchboard automatically. then the form on click events of the button call HandleButtonClick.
You could find the one that opens the admin switchboard (if it exists on the main switchboard) and call that i.e. HandleButtonClick 2

or you could just open the form

docmd.OpenForm "frmOtherSwitchboard"
Access Switchboards are table driven. The code in the OpenForm function sets a filter:

Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

    ' Move to the switchboard page that is marked as the default.
    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    Me.FilterOn = True
   
End Sub

I assume that your Admin form has not closed the switchboard, so all you need to do is set a new filter like the above code, but with the appropriate item number and argument.

If you post the contents of the switchboard table, we can assist you with the exact code.
Avatar of APD Toronto

ASKER

OK, the below is my switchboard table.

Also, the switchboard form is called Switchboard an the login popup (where the code should go) is frmAdmin.  I tried the following, but no luck...

        [Forms].[switchboard].Filter = 3
        DoCmd.Close acForm, "frmAdmin"


SwitchboardID      ItemNumber      ItemText      Command      Argument
1      0      BBB Switchboard            Default
1      1      Daily Sellers Sign-In      3      BBSalesSigninForm
1      2      Daily Sellers Sign-out      3      BBSalesSignoutForm
1      3      Make Sales Corrections      7      openBBSalesQRY
1      4      Add New Seller      3      BBSellersEntry
1      5      Add New Location      3      BBLocationsEntry
1      6      Reports      1      2
1      7      Administrative Login      3      frmAdmin
1      8      Exit      6      
2      0      BBB Switchboard Reports      0      
2      1      Daily Sales Report      4      BBDailySalesTotalSummaryReport
2      2      Location Sales Reports      3      BBLocationSearchForm
2      3      Sellers Sales Reports      2      BBSellerGrandTotalSearchForm
2      4      Nightly Sales Report      4      BBDailySalesTotalReport
2      5      BACK to Main Menu      1      1
3      0      Admin Switchboard      0      
What version access are you using/

A2003 would create the HandleButtonClick. I noticed A2007 uses macros

If A2003 you could call HandleButtonClick passing in the item number. It would be in the form design

I found one graphical example here, it does talk about > 8 items but hopefully you get the jist of things
http://www.techonthenet.com/access/switchboard/increase.php
ASKER CERTIFIED SOLUTION
Avatar of borki
borki
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note DB version is actually 2003, but it is running in Access 2007. Rockiroads is right: A native Access 2007 Db ould probably work differently.