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?
- 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:
- 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.
- If the Password is exact, the Code will fall through and proceed as normal.
- If no Password is entered or it is incorrect, Exit the HandleButtonVClick() Event.
- Notice the additional Code in Code Line #5 thru 30, does it look familiar?
- While you are at it, Uncomment Line #136 as illustrated.
- Private Function HandleButtonClick(intBtn As Integer)
-
' This function is called when a button is clicked.
-
' intBtn indicates which button was clicked.
-
-
'*************************************************************************************
-
'If this Routine is being called from the 'Main Switchboard', AND the
-
'Button Clicked is '1', User is attempting to Open the YaDa - YaDa Switchboard
-
If intBtn = 1 And Me.Caption = "Main Switchboard" Then
-
Dim strMsg As String
-
Dim strResponse As String
-
Const conPASSWORD As String = "ZeBrA"
-
-
strMsg = "A Password is required in order to Open the YaDa-YaDa Switchboard." & _
-
vbCrLf & vbCrLf & "Enter the Password in the space provided below, " & _
-
"being advised that the Password is Case Sensitive."
-
-
strResponse = InputBox$(strMsg, "Password Prompt")
-
-
If strResponse = "" Then Exit Function 'Cancel or OK with no entry
-
-
'Look for an 'exact match to ZeBrA (Case Sensitive)
-
If StrComp(conPASSWORD, strResponse, vbBinaryCompare) = 0 Then
-
'Allow Code to fall through and proceed
-
Else
-
MsgBox "The Password you entered (" & strResponse & ") is not correct!", _
-
vbCritical, "Incorrect Password"
-
Exit Function
-
End If
-
End If
-
'*************************************************************************************
-
' Constants for the commands that can be executed.
-
Const conCmdGotoSwitchboard = 1
-
Const conCmdOpenFormAdd = 2
-
Const conCmdOpenFormBrowse = 3
-
Const conCmdOpenReport = 4
-
Const conCmdCustomizeSwitchboard = 5
-
Const conCmdExitApplication = 6
-
Const conCmdRunMacro = 7
-
Const conCmdRunCode = 8
-
Const conCmdOpenPage = 9
-
-
' An error that is special cased.
-
Const conErrDoCmdCancelled = 2501
-
-
Dim con As Object
-
Dim rs As Object
-
Dim stSql As String
-
-
On Error GoTo HandleButtonClick_Err
-
-
' Find the item in the Switchboard Items table
-
' that corresponds to the button that was clicked.
-
Set con = Application.CurrentProject.Connection
-
Set rs = CreateObject("ADODB.Recordset")
-
stSql = "SELECT * FROM [Switchboard Items] "
-
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
-
rs.Open stSql, con, 1 ' 1 = adOpenKeyset
-
-
' If no item matches, report the error and exit the function.
-
If (rs.EOF) Then
-
MsgBox "There was an error reading the Switchboard Items table."
-
rs.Close
-
Set rs = Nothing
-
Set con = Nothing
-
Exit Function
-
End If
-
-
Select Case rs![Command]
-
-
' Go to another switchboard.
-
Case conCmdGotoSwitchboard
-
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
-
-
' Open a form in Add mode.
-
Case conCmdOpenFormAdd
-
DoCmd.OpenForm rs![Argument], , , , acAdd
-
-
' Open a form.
-
Case conCmdOpenFormBrowse
-
DoCmd.OpenForm rs![Argument]
-
-
' Open a report.
-
Case conCmdOpenReport
-
DoCmd.OpenReport rs![Argument], acPreview
-
-
' Customize the Switchboard.
-
Case conCmdCustomizeSwitchboard
-
' Handle the case where the Switchboard Manager
-
' is not installed (e.g. Minimal Install).
-
On Error Resume Next
-
Application.Run "ACWZMAIN.sbm_Entry"
-
If (Err <> 0) Then MsgBox "Command not available."
-
On Error GoTo 0
-
' Update the form.
-
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
-
Me.Caption = Nz(Me![ItemText], "")
-
FillOptions
-
-
' Exit the application.
-
Case conCmdExitApplication
-
CloseCurrentDatabase
-
-
' Run a macro.
-
Case conCmdRunMacro
-
DoCmd.RunMacro rs![Argument]
-
-
' Run code.
-
Case conCmdRunCode
-
Application.Run rs![Argument]
-
-
' Open a Data Access Page
-
Case conCmdOpenPage
-
DoCmd.OpenDataAccessPage rs![Argument]
-
-
' Any other command is unrecognized.
-
Case Else
-
MsgBox "Unknown option."
-
-
End Select
-
-
' Close the recordset and the database.
-
rs.Close
-
-
HandleButtonClick_Exit:
-
On Error Resume Next
-
Set rs = Nothing
-
Set con = Nothing
-
Exit Function
-
-
HandleButtonClick_Err:
-
' If the action was cancelled by the user for
-
' some reason, don't display an error message.
-
' Instead, resume on the next line.
-
If (Err = conErrDoCmdCancelled) Then
-
Resume Next
-
'ElseIf Err.Number = -2147352560 Then 'Nothing
-
Else
-
MsgBox "There was an error executing the command." & Err.Number, vbCritical
-
Resume HandleButtonClick_Exit
-
End If
-
End Function
- Download the Attachment to really see what is going on.
10 2828
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
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?
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
I'm not clear on how calling a switchboard page would turn off the wizard. Could you help me understand that?
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.
- 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:
- 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.
- If the Password is exact, the Code will fall through and proceed as normal.
- If no Password is entered or it is incorrect, Exit the HandleButtonVClick() Event.
- Notice the additional Code in Code Line #5 thru 30, does it look familiar?
- While you are at it, Uncomment Line #136 as illustrated.
- Private Function HandleButtonClick(intBtn As Integer)
-
' This function is called when a button is clicked.
-
' intBtn indicates which button was clicked.
-
-
'*************************************************************************************
-
'If this Routine is being called from the 'Main Switchboard', AND the
-
'Button Clicked is '1', User is attempting to Open the YaDa - YaDa Switchboard
-
If intBtn = 1 And Me.Caption = "Main Switchboard" Then
-
Dim strMsg As String
-
Dim strResponse As String
-
Const conPASSWORD As String = "ZeBrA"
-
-
strMsg = "A Password is required in order to Open the YaDa-YaDa Switchboard." & _
-
vbCrLf & vbCrLf & "Enter the Password in the space provided below, " & _
-
"being advised that the Password is Case Sensitive."
-
-
strResponse = InputBox$(strMsg, "Password Prompt")
-
-
If strResponse = "" Then Exit Function 'Cancel or OK with no entry
-
-
'Look for an 'exact match to ZeBrA (Case Sensitive)
-
If StrComp(conPASSWORD, strResponse, vbBinaryCompare) = 0 Then
-
'Allow Code to fall through and proceed
-
Else
-
MsgBox "The Password you entered (" & strResponse & ") is not correct!", _
-
vbCritical, "Incorrect Password"
-
Exit Function
-
End If
-
End If
-
'*************************************************************************************
-
' Constants for the commands that can be executed.
-
Const conCmdGotoSwitchboard = 1
-
Const conCmdOpenFormAdd = 2
-
Const conCmdOpenFormBrowse = 3
-
Const conCmdOpenReport = 4
-
Const conCmdCustomizeSwitchboard = 5
-
Const conCmdExitApplication = 6
-
Const conCmdRunMacro = 7
-
Const conCmdRunCode = 8
-
Const conCmdOpenPage = 9
-
-
' An error that is special cased.
-
Const conErrDoCmdCancelled = 2501
-
-
Dim con As Object
-
Dim rs As Object
-
Dim stSql As String
-
-
On Error GoTo HandleButtonClick_Err
-
-
' Find the item in the Switchboard Items table
-
' that corresponds to the button that was clicked.
-
Set con = Application.CurrentProject.Connection
-
Set rs = CreateObject("ADODB.Recordset")
-
stSql = "SELECT * FROM [Switchboard Items] "
-
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
-
rs.Open stSql, con, 1 ' 1 = adOpenKeyset
-
-
' If no item matches, report the error and exit the function.
-
If (rs.EOF) Then
-
MsgBox "There was an error reading the Switchboard Items table."
-
rs.Close
-
Set rs = Nothing
-
Set con = Nothing
-
Exit Function
-
End If
-
-
Select Case rs![Command]
-
-
' Go to another switchboard.
-
Case conCmdGotoSwitchboard
-
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
-
-
' Open a form in Add mode.
-
Case conCmdOpenFormAdd
-
DoCmd.OpenForm rs![Argument], , , , acAdd
-
-
' Open a form.
-
Case conCmdOpenFormBrowse
-
DoCmd.OpenForm rs![Argument]
-
-
' Open a report.
-
Case conCmdOpenReport
-
DoCmd.OpenReport rs![Argument], acPreview
-
-
' Customize the Switchboard.
-
Case conCmdCustomizeSwitchboard
-
' Handle the case where the Switchboard Manager
-
' is not installed (e.g. Minimal Install).
-
On Error Resume Next
-
Application.Run "ACWZMAIN.sbm_Entry"
-
If (Err <> 0) Then MsgBox "Command not available."
-
On Error GoTo 0
-
' Update the form.
-
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
-
Me.Caption = Nz(Me![ItemText], "")
-
FillOptions
-
-
' Exit the application.
-
Case conCmdExitApplication
-
CloseCurrentDatabase
-
-
' Run a macro.
-
Case conCmdRunMacro
-
DoCmd.RunMacro rs![Argument]
-
-
' Run code.
-
Case conCmdRunCode
-
Application.Run rs![Argument]
-
-
' Open a Data Access Page
-
Case conCmdOpenPage
-
DoCmd.OpenDataAccessPage rs![Argument]
-
-
' Any other command is unrecognized.
-
Case Else
-
MsgBox "Unknown option."
-
-
End Select
-
-
' Close the recordset and the database.
-
rs.Close
-
-
HandleButtonClick_Exit:
-
On Error Resume Next
-
Set rs = Nothing
-
Set con = Nothing
-
Exit Function
-
-
HandleButtonClick_Err:
-
' If the action was cancelled by the user for
-
' some reason, don't display an error message.
-
' Instead, resume on the next line.
-
If (Err = conErrDoCmdCancelled) Then
-
Resume Next
-
'ElseIf Err.Number = -2147352560 Then 'Nothing
-
Else
-
MsgBox "There was an error executing the command." & Err.Number, vbCritical
-
Resume HandleButtonClick_Exit
-
End If
-
End Function
- Download the Attachment to really see what is going on.
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.
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.
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...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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>
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
|
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...
| |