473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I call a switchboard from within a code module?

sueb
379 256MB
I have a piece of code that is triggered from a switchboard, asks for a password, and then opens a form.

I'd like it to open its own switchboard. What's the syntax for that?
Jan 19 '11 #1

✓ answered by ADezii

  1. I did come up with a little trickery that will enable you to Open another 'Wizard Generated Switchboard' only if the correct Password is entered. I did this by adding additional Code to the HandleButtonClick() Function in the Form Module which will:
    1. Check the Switchboard Caption and which Button was clicked. Only 1 exact combination of each exists that will Open another Switchboard. In this case is is Button 1 on the Main Switchboard to Open the YaDa - YaDa Switchboard.
    2. If the Password is exact, the Code will fall through and proceed as normal.
    3. If no Password is entered or it is incorrect, Exit the HandleButtonVClick() Event.
    4. Notice the additional Code in Code Line #5 thru 30, does it look familiar?
    5. While you are at it, Uncomment Line #136 as illustrated.
    Expand|Select|Wrap|Line Numbers
    1. Private Function HandleButtonClick(intBtn As Integer)
    2. ' This function is called when a button is clicked.
    3. ' intBtn indicates which button was clicked.
    4.  
    5. '*************************************************************************************
    6. 'If this Routine is being called from the 'Main Switchboard', AND the
    7. 'Button Clicked is '1', User is attempting to Open the YaDa - YaDa Switchboard
    8. If intBtn = 1 And Me.Caption = "Main Switchboard" Then
    9.   Dim strMsg As String
    10.   Dim strResponse As String
    11.   Const conPASSWORD As String = "ZeBrA"
    12.  
    13.   strMsg = "A Password is required in order to Open the YaDa-YaDa Switchboard." & _
    14.             vbCrLf & vbCrLf & "Enter the Password in the space provided below, " & _
    15.            "being advised that the Password is Case Sensitive."
    16.  
    17.   strResponse = InputBox$(strMsg, "Password Prompt")
    18.  
    19.   If strResponse = "" Then Exit Function      'Cancel or OK with no entry
    20.  
    21.   'Look for an 'exact match to ZeBrA (Case Sensitive)
    22.   If StrComp(conPASSWORD, strResponse, vbBinaryCompare) = 0 Then
    23.     'Allow Code to fall through and proceed
    24.   Else
    25.     MsgBox "The Password you entered (" & strResponse & ") is not correct!", _
    26.             vbCritical, "Incorrect Password"
    27.               Exit Function
    28.   End If
    29. End If
    30. '*************************************************************************************
    31.     ' Constants for the commands that can be executed.
    32.     Const conCmdGotoSwitchboard = 1
    33.     Const conCmdOpenFormAdd = 2
    34.     Const conCmdOpenFormBrowse = 3
    35.     Const conCmdOpenReport = 4
    36.     Const conCmdCustomizeSwitchboard = 5
    37.     Const conCmdExitApplication = 6
    38.     Const conCmdRunMacro = 7
    39.     Const conCmdRunCode = 8
    40.     Const conCmdOpenPage = 9
    41.  
    42.     ' An error that is special cased.
    43.     Const conErrDoCmdCancelled = 2501
    44.  
    45.     Dim con As Object
    46.     Dim rs As Object
    47.     Dim stSql As String
    48.  
    49. On Error GoTo HandleButtonClick_Err
    50.  
    51.     ' Find the item in the Switchboard Items table
    52.     ' that corresponds to the button that was clicked.
    53.     Set con = Application.CurrentProject.Connection
    54.     Set rs = CreateObject("ADODB.Recordset")
    55.     stSql = "SELECT * FROM [Switchboard Items] "
    56.     stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
    57.     rs.Open stSql, con, 1    ' 1 = adOpenKeyset
    58.  
    59.     ' If no item matches, report the error and exit the function.
    60.     If (rs.EOF) Then
    61.         MsgBox "There was an error reading the Switchboard Items table."
    62.         rs.Close
    63.         Set rs = Nothing
    64.         Set con = Nothing
    65.         Exit Function
    66.     End If
    67.  
    68.     Select Case rs![Command]
    69.  
    70.         ' Go to another switchboard.
    71.         Case conCmdGotoSwitchboard
    72.             Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
    73.  
    74.         ' Open a form in Add mode.
    75.         Case conCmdOpenFormAdd
    76.             DoCmd.OpenForm rs![Argument], , , , acAdd
    77.  
    78.         ' Open a form.
    79.         Case conCmdOpenFormBrowse
    80.             DoCmd.OpenForm rs![Argument]
    81.  
    82.         ' Open a report.
    83.         Case conCmdOpenReport
    84.             DoCmd.OpenReport rs![Argument], acPreview
    85.  
    86.         ' Customize the Switchboard.
    87.         Case conCmdCustomizeSwitchboard
    88.             ' Handle the case where the Switchboard Manager
    89.             ' is not installed (e.g. Minimal Install).
    90.             On Error Resume Next
    91.             Application.Run "ACWZMAIN.sbm_Entry"
    92.             If (Err <> 0) Then MsgBox "Command not available."
    93.             On Error GoTo 0
    94.             ' Update the form.
    95.             Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    96.             Me.Caption = Nz(Me![ItemText], "")
    97.             FillOptions
    98.  
    99.         ' Exit the application.
    100.         Case conCmdExitApplication
    101.             CloseCurrentDatabase
    102.  
    103.         ' Run a macro.
    104.         Case conCmdRunMacro
    105.             DoCmd.RunMacro rs![Argument]
    106.  
    107.         ' Run code.
    108.         Case conCmdRunCode
    109.             Application.Run rs![Argument]
    110.  
    111.         ' Open a Data Access Page
    112.         Case conCmdOpenPage
    113.             DoCmd.OpenDataAccessPage rs![Argument]
    114.  
    115.         ' Any other command is unrecognized.
    116.         Case Else
    117.             MsgBox "Unknown option."
    118.  
    119.     End Select
    120.  
    121.     ' Close the recordset and the database.
    122.     rs.Close
    123.  
    124. HandleButtonClick_Exit:
    125. On Error Resume Next
    126.     Set rs = Nothing
    127.     Set con = Nothing
    128.     Exit Function
    129.  
    130. HandleButtonClick_Err:
    131.     ' If the action was cancelled by the user for
    132.     ' some reason, don't display an error message.
    133.     ' Instead, resume on the next line.
    134.     If (Err = conErrDoCmdCancelled) Then
    135.         Resume Next
    136.     'ElseIf Err.Number = -2147352560 Then    'Nothing
    137.     Else
    138.         MsgBox "There was an error executing the command." & Err.Number, vbCritical
    139.         Resume HandleButtonClick_Exit
    140.     End If
    141. End Function
  2. Download the Attachment to really see what is going on.

10 2828
Stewart Ross
2,545 Expert Mod 2GB
Hi Sue. It depends what you mean by 'switchboard'. If you have designed a custom switchboard form yourself it can be opened like any other form by using the DoCmd.OpenForm method in VBA from within whatever form or code segment you want to launch it.

If you mean you want to open or customise a version of the standard wizard-designed switchboard the short answer is that you would be ill-advised to do so, as the different switchboard 'pages' you see in the switchboard are actually code-customised variations on the same page, with changes to the captions and responses for each different page or subpage displayed according to values stored within a switchboard options table built by the switchboard wizard routines.

It is possible to customise standard switchboards to some degree, but the basic functionality of the button choices and options displayed can't be altered without losing the ability to manage the switchboard using the built-in wizard.

-Stewart
Jan 19 '11 #2
sueb
379 256MB
I don't want to modify the basic functionality--I just want to create a switchboard "sub-page" that only gets call through a little piece of code.

Here's the picture: I have a regular, main switchboard, with sub-pages and all, and one of the choices calls a piece of code that asks for a password. Once the user has entered the correct password, I'd like to put up a sub-page that has a couple of choices on it. (These choices would each just open a form.)

That's it. I'd continue to manage all the switchboard pages through the built-in wizard, and I don't need them to do anything tricky.

What do you think?
Jan 19 '11 #3
Stewart Ross
2,545 Expert Mod 2GB
In general it is not possible to do what you ask, Sue, as the switchboard sub-pages are NOT independent. There is only one form, and the sub-menus you see are all arising from the switchboard's wizard-created code in conjunction with the table storing all of the switchboard options.

If you look at the switchboard form's design it appears as a set of uncaptioned blank buttons. The switchboard table created by the switchboard wizard in conjunction with the active code on the form determines which 'page' is currently shown, which buttons to make visible, the captions for the buttons, and the options which are executed in response to a particular button being pressed.

Although it would be possible to execute commands to force the switchboard to execute a particular option, in general this would mean you could not use the built-in 'manage switchboard' options to assist you any further if you go this route.

-Stewart
Jan 19 '11 #4
sueb
379 256MB
I'm not clear on how calling a switchboard page would turn off the wizard. Could you help me understand that?
Jan 19 '11 #5
ADezii
8,834 Expert 8TB
I think there may be a 'rogue' method of conditionally opening another Wizard Generated Switchboard from a Main Switchboard. I've done something similar in the past, give me a little time and I'll see if I can come up with the Code.
Jan 20 '11 #6
sueb
379 256MB
Thanks, ADezii!
Jan 20 '11 #7
ADezii
8,834 Expert 8TB
  1. I did come up with a little trickery that will enable you to Open another 'Wizard Generated Switchboard' only if the correct Password is entered. I did this by adding additional Code to the HandleButtonClick() Function in the Form Module which will:
    1. Check the Switchboard Caption and which Button was clicked. Only 1 exact combination of each exists that will Open another Switchboard. In this case is is Button 1 on the Main Switchboard to Open the YaDa - YaDa Switchboard.
    2. If the Password is exact, the Code will fall through and proceed as normal.
    3. If no Password is entered or it is incorrect, Exit the HandleButtonVClick() Event.
    4. Notice the additional Code in Code Line #5 thru 30, does it look familiar?
    5. While you are at it, Uncomment Line #136 as illustrated.
    Expand|Select|Wrap|Line Numbers
    1. Private Function HandleButtonClick(intBtn As Integer)
    2. ' This function is called when a button is clicked.
    3. ' intBtn indicates which button was clicked.
    4.  
    5. '*************************************************************************************
    6. 'If this Routine is being called from the 'Main Switchboard', AND the
    7. 'Button Clicked is '1', User is attempting to Open the YaDa - YaDa Switchboard
    8. If intBtn = 1 And Me.Caption = "Main Switchboard" Then
    9.   Dim strMsg As String
    10.   Dim strResponse As String
    11.   Const conPASSWORD As String = "ZeBrA"
    12.  
    13.   strMsg = "A Password is required in order to Open the YaDa-YaDa Switchboard." & _
    14.             vbCrLf & vbCrLf & "Enter the Password in the space provided below, " & _
    15.            "being advised that the Password is Case Sensitive."
    16.  
    17.   strResponse = InputBox$(strMsg, "Password Prompt")
    18.  
    19.   If strResponse = "" Then Exit Function      'Cancel or OK with no entry
    20.  
    21.   'Look for an 'exact match to ZeBrA (Case Sensitive)
    22.   If StrComp(conPASSWORD, strResponse, vbBinaryCompare) = 0 Then
    23.     'Allow Code to fall through and proceed
    24.   Else
    25.     MsgBox "The Password you entered (" & strResponse & ") is not correct!", _
    26.             vbCritical, "Incorrect Password"
    27.               Exit Function
    28.   End If
    29. End If
    30. '*************************************************************************************
    31.     ' Constants for the commands that can be executed.
    32.     Const conCmdGotoSwitchboard = 1
    33.     Const conCmdOpenFormAdd = 2
    34.     Const conCmdOpenFormBrowse = 3
    35.     Const conCmdOpenReport = 4
    36.     Const conCmdCustomizeSwitchboard = 5
    37.     Const conCmdExitApplication = 6
    38.     Const conCmdRunMacro = 7
    39.     Const conCmdRunCode = 8
    40.     Const conCmdOpenPage = 9
    41.  
    42.     ' An error that is special cased.
    43.     Const conErrDoCmdCancelled = 2501
    44.  
    45.     Dim con As Object
    46.     Dim rs As Object
    47.     Dim stSql As String
    48.  
    49. On Error GoTo HandleButtonClick_Err
    50.  
    51.     ' Find the item in the Switchboard Items table
    52.     ' that corresponds to the button that was clicked.
    53.     Set con = Application.CurrentProject.Connection
    54.     Set rs = CreateObject("ADODB.Recordset")
    55.     stSql = "SELECT * FROM [Switchboard Items] "
    56.     stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
    57.     rs.Open stSql, con, 1    ' 1 = adOpenKeyset
    58.  
    59.     ' If no item matches, report the error and exit the function.
    60.     If (rs.EOF) Then
    61.         MsgBox "There was an error reading the Switchboard Items table."
    62.         rs.Close
    63.         Set rs = Nothing
    64.         Set con = Nothing
    65.         Exit Function
    66.     End If
    67.  
    68.     Select Case rs![Command]
    69.  
    70.         ' Go to another switchboard.
    71.         Case conCmdGotoSwitchboard
    72.             Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
    73.  
    74.         ' Open a form in Add mode.
    75.         Case conCmdOpenFormAdd
    76.             DoCmd.OpenForm rs![Argument], , , , acAdd
    77.  
    78.         ' Open a form.
    79.         Case conCmdOpenFormBrowse
    80.             DoCmd.OpenForm rs![Argument]
    81.  
    82.         ' Open a report.
    83.         Case conCmdOpenReport
    84.             DoCmd.OpenReport rs![Argument], acPreview
    85.  
    86.         ' Customize the Switchboard.
    87.         Case conCmdCustomizeSwitchboard
    88.             ' Handle the case where the Switchboard Manager
    89.             ' is not installed (e.g. Minimal Install).
    90.             On Error Resume Next
    91.             Application.Run "ACWZMAIN.sbm_Entry"
    92.             If (Err <> 0) Then MsgBox "Command not available."
    93.             On Error GoTo 0
    94.             ' Update the form.
    95.             Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    96.             Me.Caption = Nz(Me![ItemText], "")
    97.             FillOptions
    98.  
    99.         ' Exit the application.
    100.         Case conCmdExitApplication
    101.             CloseCurrentDatabase
    102.  
    103.         ' Run a macro.
    104.         Case conCmdRunMacro
    105.             DoCmd.RunMacro rs![Argument]
    106.  
    107.         ' Run code.
    108.         Case conCmdRunCode
    109.             Application.Run rs![Argument]
    110.  
    111.         ' Open a Data Access Page
    112.         Case conCmdOpenPage
    113.             DoCmd.OpenDataAccessPage rs![Argument]
    114.  
    115.         ' Any other command is unrecognized.
    116.         Case Else
    117.             MsgBox "Unknown option."
    118.  
    119.     End Select
    120.  
    121.     ' Close the recordset and the database.
    122.     rs.Close
    123.  
    124. HandleButtonClick_Exit:
    125. On Error Resume Next
    126.     Set rs = Nothing
    127.     Set con = Nothing
    128.     Exit Function
    129.  
    130. HandleButtonClick_Err:
    131.     ' If the action was cancelled by the user for
    132.     ' some reason, don't display an error message.
    133.     ' Instead, resume on the next line.
    134.     If (Err = conErrDoCmdCancelled) Then
    135.         Resume Next
    136.     'ElseIf Err.Number = -2147352560 Then    'Nothing
    137.     Else
    138.         MsgBox "There was an error executing the command." & Err.Number, vbCritical
    139.         Resume HandleButtonClick_Exit
    140.     End If
    141. End Function
  2. Download the Attachment to really see what is going on.
Attached Files
File Type: zip Password_2.zip (27.1 KB, 100 views)
Jan 20 '11 #8
sueb
379 256MB
Thanks for this, ADezii, but I think you have just convinced me that I don't want to do this! This is way complicated for the benefit of going outside the switchboard scheme. I guess I'll just not password-protect the new menu option. It's not like people aren't allowed to access it, but some people wouldn't know what to do with it if they stumbled into it.

I just thought there would be a simple way to insert a checkpoint on menu options.

Thanks anyway, though. I'm going to mark your answer, since it does actually answer the need. That way people will know how to do this if they have a crying need.
Jan 20 '11 #9
ADezii
8,834 Expert 8TB
Stewart addressed the issue very eloquently in Post #4 in that Wizard Generated Switchboards are not independent entities, but a Single Form dynamically re-generated based on certain conditions. Given this, I do believe that there is no 'simple' solution to your question, only that which I have provided for you.
Jan 20 '11 #10
sueb
379 256MB
Yes, I guess I "get" that now. :D

I was assuming a very different implementation, I think--sort of like just a series of linked forms or something. Hmmm... I wonder if something like that would work for me? I mean, what if I created forms that behaved like a switchboard? Maybe I'll look into that...
Jan 20 '11 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Justin Koivisto | last post by:
OK, here's one of the rare times where I call out to all of you. ;) I need to implement a promotional discount code module into osCommerce 2.2 Milestone 2. I've never created an OSC module...
4
by: Ram | last post by:
I have a code module with main as subroutine name. How to launch a Windows form from here. Thanks, Ram
3
by: Oenone | last post by:
I am trying to write a generic piece of code that I can copy between projects that uses the current project's root namespace as part of its function. I can easily retrieve this value when I am...
1
by: Thomas Heller | last post by:
I'm using the code module to implement an interactive interpreter console in a GUI application, the interpreter running in a separate thread. To provide clean shutdown of the application, I have...
0
by: Max Kubierschky | last post by:
I want to access some static (non changing) files from within a module (e.g icons, style sheets) and distribute them together with the module. Can I place the inside the module folder? If so, how...
0
by: Mike | last post by:
Hi. I have a vb.net/asp.net application, originally created in VS2003. I'm upgrading it to VS2005, and have found that Public Functions in a module are no longer accessable in my application. ...
1
by: santaferubber | last post by:
The first query returns me the results from multiple databases, the second does the same thing except it puts the result into a #temp table? Could someone please show me an example of this using...
4
by: sajithkahawatta | last post by:
i want to call a java script function from code behind. in page1.aspx page i placed script' <script language="javascript"> function SetSelected() { infoTextBox.select(); } </script>
3
by: Salad | last post by:
I'm asking this for curiosity's sake. Is there a code module size limit? I looked at Access Specifications in help and didn't notice a code limit size. For some odd reason I was under the...
10
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following three files. 1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to populate a simple <asp:ListBoxcontrol. 2. The UserDetails.cs file creates a Namespace...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.