Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating code to open a specific switchboard? 2

Status
Not open for further replies.

Regression

IS-IT--Management
Oct 10, 2002
17
US
Hey All,

I am trying to pass word protect a switch board. I have the password check portion working fine. The problem I am haveing is I would like a specific sub switchboard to open and not the main switch board when the correct password is entered.

Could anyone tell me what aruments I need to send to make this work.

I can only seem to get it to open the main switchboard.

Thanks
 
Hi,

This is what I have to get to a certain part of the switchboard

Private Sub CmdElsie_Click()
On Error GoTo Err_CmdElsie_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Switchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Switchboard.Filter = "[ItemNumber] = 0 AND [Argument] = 'Elsie' "
Forms!Switchboard.FilterOn = True

DoCmd.Close acForm, "FrmMainMenu"

Exit_CmdElsie_Click:
Exit Sub

Err_CmdElsie_Click:
MsgBox Err.Description
Resume Exit_CmdElsie_Click

End Sub

Where Elsie is the name of the part of the swithcboard I want to open. This info can be got from the Swithcboard table

Hope this helps, let me know
Rob! [Bigcheeks]
Process and Procedure are the last hiding place of people without the wit
and wisdom to do their job properly.
 
Rob,

Thanks for your reply this sent me down the right track.

 
RobPotts

I am precisely after a similar solution. But I need little clarity on the code you have posted. My situation is not very different from the one described by Regression. I wish to restrict a user to a second instance of the switchboard when he clicks a button on the opening menu. I have set up a form and with an underlying table of users to see the second instance of the switchboard but not too sure how to use the code in the Adnmin form to open the second instance of switrchboard. Could you please explan where do you propose your code to appear if the button is linked to a admin form.

Will most appreciate your help.


Cheers

AK
 
Hi Khwaja,

I sorry its taken so long to get back to you. I'm not entirly sure how you password check works but I would guess you could just put an if password correct (not sure what code you using to check the password is correct). Then if true put the code in above with the name of yourpage 2 where I've got Elsie. Make sure that the argument in the swithchboard items is then set to the name above. In the esle I guess you would just close the password form.

If you need any clarification just drop a line, I'll try to be a bit quicker, also if you put your code for checking password that might help.

Rob! [Bigcheeks]
Process and Procedure are the last hiding place of people without the wit
and wisdom to do their job properly.
 
Thanks a lot Rob. I am using the following code to open a form and get user input and then open the form. As you suggested, this code should either sit as part of the switchboard code or on its own with the ability to open the form:

DoCmd.OpenForm "frmCriteriaSupport"

Code is as under:
Private Sub cmdOK_Click()
If DLookup("[Password]", "N_tblPassword", _
"[USERID] = [Forms]![frmPasswordA]![txtUSERID]") = [Forms]![frmPasswordA]![txtPassword] Then

'MsgBox "Password Accepted!"
DoCmd.OpenForm "frmCriteriaSupport"
DoCmd.Close acForm, "frmPasswordA"


ElseIf IsNull(txtPassword) Then
MsgBox "The password field cannot be blank. Please type your password."
DoCmd.GoToControl "txtPassword"
Else
MsgBox "Password is incorrect. Please try again or Contact HR SM Ops for assistance."
DoCmd.GoToControl "txtPassword"
txtPassword.Text = ""
End If
End Sub

What I am struggling with is where to place this form in the switchboard code and how to relate to your code. Will apprecaite if you could take the oroginal code and show me where you inserted bits of codes. I am reproducing switchboard code here but not sure whether it is the right part. Assuming that it would be filloptions function, following is the code:

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

' 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

' An error that is special cased.
Const conErrDoCmdCancelled = 2501

Dim dbs As Database
Dim rst As Recordset

On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)
rst.FindFirst "[SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn

' If no item matches, report the error and exit the function.
If (rst.NoMatch) Then
MsgBox "There was an error reading the Switchboard Items table."
rst.Close
dbs.Close
Exit Function
End If

Select Case rst![Command]

' Go to another switchboard.
Case conCmdGotoSwitchboard
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rst![Argument]

' Open a form in Add mode.
Case conCmdOpenFormAdd
DoCmd.OpenForm rst![Argument], , , , acAdd

' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rst![Argument]

' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rst![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 "WZMAIN80.sbm_Entry"
If (Err <> 0) Then MsgBox &quot;Command not available.&quot;
On Error GoTo 0
' Update the form.
Me.Filter = &quot;[ItemNumber] = 0 AND [Argument] = 'Default' &quot;
Me.Caption = Nz(Me![ItemText], &quot;&quot;)
FillOptions

' Exit the application.
Case conCmdExitApplication
'CloseCurrentDatabase
DoCmd.Quit
' Run a macro.
Case conCmdRunMacro
DoCmd.RunMacro rst![Argument]

' Run code.
Case conCmdRunCode
Application.Run rst![Argument]

' Any other command is unrecognized.
Case Else
MsgBox &quot;Unknown option.&quot;

End Select

' Close the recordset and the database.
rst.Close
dbs.Close

HandleButtonClick_Exit:
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
Else
MsgBox &quot;There was an error executing the command.&quot;, vbCritical
Resume HandleButtonClick_Exit
End If

End Function
Cheers

AK
 
AK,

I've had a look and this is what I've come up with. One of the buttons on the switch board opens a form called &quot;FormPasswordA&quot;. Then in that form you have unbound feilds called &quot;txtPassword&quot; and &quot;txtUSERID&quot; and a button called cmdOK. if in the on click code you use this code

Private Sub cmdOK_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = &quot;Switchboard&quot;

If DLookup(&quot;[Password]&quot;, &quot;N_tblPassword&quot;, _
&quot;[USERID] = [Forms]![frmPasswordA]![txtUSERID]&quot;) = [Forms]![frmPasswordA]![txtPassword] Then

'MsgBox &quot;Password Accepted!&quot;
DoCmd.OpenForm &quot;frmCriteriaSupport&quot;
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Switchboard.Filter = &quot;[ItemNumber] = 0 AND [Argument] = 'Name of the switch page to go to' &quot;
Forms!Switchboard.FilterOn = True

DoCmd.Close acForm, &quot;frmPasswordA&quot;


ElseIf IsNull(txtPassword) Then
MsgBox &quot;The password field cannot be blank. Please type your password.&quot;
DoCmd.GoToControl &quot;txtPassword&quot;
Else
MsgBox &quot;Password is incorrect. Please try again or Contact HR SM Ops for assistance.&quot;
DoCmd.GoToControl &quot;txtPassword&quot;
txtPassword.Text = &quot;&quot;
End If
End Sub

Then go into your switchboard items table and find the appropriate menues, these are defined by the switchboardID, then find the item number 0 for this menu, and in its Arguments it'll probably be blank, in here put some text which you will use to identify that menu page. Also add this name to the code (the blue bit).

Now when you open the password form, if you type the correct password the switch board page will open, along with your for (Hightlighted in red). Now just make sure that none of the buttons on you switchboard open this page.

Hope this clears stuff up. If you need any more help just drop me a line, I'll e-mail you a sample database if you want. Rob! [Bigcheeks]
Process and Procedure are the last hiding place of people without the wit
and wisdom to do their job properly.
 
Very well done. I tried and it worked very well. Cannot thank you enough. The password I am using is not doing what it is supposed to. Would you be kind enough to help me fix this code. After incorporating your bit, my code is as under. At the moment if you cancel the password dialogue, it opens the report anyway which it shouldn't. Could there be something wrong with the code or the way switchboard is being handled. In case, you would like to send me your db or see mine, please ontact me on akhwaja@woolworths.com.au

Private Sub cmdOK_Click()
On Error GoTo ErrorHandling_Err

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = &quot;Switchboard&quot;

If DLookup(&quot;[Password]&quot;, &quot;N_tblPassword&quot;, _
&quot;[USERID] = [Forms]![frmPasswordA]![txtUSERID]&quot;) = [Forms]![frmPasswordA]![txtPassword] Then

'MsgBox &quot;Password Accepted!&quot;
'DoCmd.OpenForm &quot;frmStoresExt&quot;
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Switchboard.Filter = &quot;[ItemNumber] = 0 AND [Argument] = 'AK' &quot;

DoCmd.Close acForm, &quot;frmPasswordA&quot;
ElseIf IsNull(txtUSERID) Then
MsgBox &quot;The USERID field cannot be blank. Please type a valid USERID.&quot;
DoCmd.GoToControl &quot;txtUSERID&quot;
txtPassword.Enabled = False

ElseIf DLookup(&quot;[Password]&quot;, &quot;N_tblPassword&quot;, _
&quot;[USERID] = [Forms]![frmPasswordA]![txtUSERID]&quot;) <> [Forms]![frmPasswordA]![txtPassword] Then
MsgBox &quot;You entered an invalid USERID. Please type a valid USERID.&quot;
DoCmd.GoToControl &quot;txtUSERID&quot;
txtPassword.Enabled = False


ElseIf IsNull(txtPassword) Then
MsgBox &quot;The password field cannot be blank. Please type your password.&quot;
DoCmd.GoToControl &quot;txtPassword&quot;
Else
MsgBox &quot;Password is incorrect. Please try again or Contact HR SM Ops for assistance.&quot;
DoCmd.GoToControl &quot;txtPassword&quot;
txtPassword.Text = &quot;&quot;
End If
ErrorHandling_Exit:

Exit Sub

ErrorHandling_Err:
Select Case Err.Number

Case 2210
MsgBox &quot;You entered an invalid USERID. Please type a valid USERID.&quot;

Case 4444
MsgBox &quot;The password field cannot be blank. Please type your password.&quot;
Case Else
MsgBox Err.Description & &quot; - &quot; & Err.Number
End Select
End Sub Cheers

AK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top