Need Help determining SwitchboardID and ItemNumber

randolphoralph

Registered User.
Local time
Today, 10:14
Joined
Aug 4, 2008
Messages
101
Editing SwitchboardID and ItemNumber

I am trying to implement the following in order to password protect an area on my Switchboard.

Here is a link to what I am trying to do...

www.daniweb.com/code/snippet216570.html

The problem is that when I follow the instructions on lines 85-141 I can not seem to get the code to work. I am having problems editing the code for the SwitchboardID and ItemNumber.

The button I want to set the password for is showing as SwitchboardID = 1 and ItemNumber = 1 (in the switchboard table)

I have edited the code at the link above and here is what I have....

Code:
'Below is the modified code I put into the Switch board
    Dim Hold As Variant
    Dim tmpKey As Long
    Dim I As Integer
    Dim rs1 As DAO.Recordset
    Dim db As DAO.Database
 
    Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
 
'Below is where you set the button
    [B]If Val([ItemNumber]) = 1 And Val([SwitchboardID]) = 1[/B] Then
            DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
            Hold = MyPassword
            Set db = CurrentDb
            Set rs1 = db.OpenRecordset("tblPassword", dbOpenTable)
                 If rs1.NoMatch Then
                     MsgBox "Sorry cannot find password    information. Try Again"
                     Cancel = -1
            ' Move to the switchboard page that is marked as the default.
                     Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
                     Me.FilterOn = True
    ElseIf Not (rs1![KeyCode] = KeyCode(CStr(Hold))) Then
                     MsgBox "Sorry password does not match Key Code." & _
                     "Try again.", vbOKOnly, "Incorrect Password"
                     Cancel = -1
            ' Move to the switchboard page that is marked as the default.
                    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
                    Me.FilterOn = True
             End If
    rs1.Close
    db.Close
   End If

I can not seem to get this to work....no matter what I do.

When I click on the button on the switchboard it just opens the Form and does not prompt for a password with the frmPassword form.

Any thoughts would be greatly appreciated.
 
Last edited:
Here is the database that I am using. Hopefully this helps cause I am going crazy trying to figure this out. :)

The password for the Employee Form has been set to page
 

Attachments

ok - in this bit of your code

'Below is where you set the button
If Val([ItemNumber]) = 1 And Val([SwitchboardID]) = 1 Then
DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
Hold = MyPassword
Set db = CurrentDb
Set rs1 = db.OpenRecordset("tblPassword", dbOpenTable)
If rs1.NoMatch Then
MsgBox "Sorry cannot find password information. Try Again"
Cancel = -1


DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
this line does nothing - it opens a form, and waits for you to close it.
if you need to get a password from a user, then you might use an inputbox. the trouble is that you cant use masked characters in an input box, so other users could see the password. if not you need code in the frmpassword to save the password. try with an inputbox, to get it working then go on from there.

Hold = MyPassword
now you have got the password into variables? controls? called hold or mypasssword. what you need to do is a dlookup to see if the password is acceptable

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tblPassword", dbOpenTable)
If rs1.NoMatch Then
MsgBox "Sorry cannot find password information. Try Again"

but this code doesnt quite do it either. this is just opening the password table, but is not searching for anything.

Cancel = -1
finally, although you set cancel to true, you ALSO need to exit the sub here - or the code will contiune to run to an exit point.

Hope this helps.


Having said ALL this, specfically modifying the code for certain menu options seems heavy-handed. I would add a column to the switchboard items table, called "NeedPassword", and test that - rather than explicitly checking particular menu options.

does the same thing, but it's easier to amend your app for other menu items requiring the same functionality.
 
Last edited:
sorry

I've looked at this, but haven't got time to fix it now.

the password form is ok - its the switchboard code that isnt

you have put the code into the wrong area of the switchboard

in the handlebutton click event, you have added the code into the bit that deal with the "move to a new switchboard" type action (this is a command setting of 1 in the switchboard items table) - but opening a form is action setting 2 or 3 - depending on the mode.
 
Last edited:
OK - I decided I could help, so try this

I added an extra field to the switchboard items table, and an extra column to the passwords table, to avoid having to mess with your encryption code

i moved the code around in the handle button click event - hopefully you can see what is going on now.


View attachment testpwd.zip
 
gemma-the-husky,

This worked perfectly. Thank you.

Thanks to everyone for looking at this. :)
 
gemma-the-husky,

How would I edit the code to make this work for more than one password?

For example if I have another area on the switchboard that Needs a Password, but want to use a different password and ObjectName in the tblpassword.

I am thinking that I need to somehow include the ObjectName (from the tblpassword) in the switchboard code where the DLookup is.
 
i am not sure exactly how you want to do this.

you have a password, (which encrypts into another string)

you test a table to see if the password (or the encrypted version) exists in the password table. If it does then you can find the other details about the password. (in this case it may be beeter to use a recordset, rather than a dlookup

Now, how you react to the other information is up to your programme.

One issue may be is you maintain the passwords - eg could the same password apply to different users/classes. If not, how do you manage them - becuase you now you will find that the dlookup (or search) finds the first, but not necessearily the correct) instance of the password.

And be aware that it is hard to keep static passwords confidential anyway. Users share them/disclose them etc etc, especially in a non-personal work environment

Good luck with your project
 
I have removed the encrypted password and I am using two fields on the tblpassword. ObjectName and Raw.

I was hoping to use DLookup to match the Raw and ObjectName.
 

Users who are viewing this thread

Back
Top Bottom