PDA

View Full Version : Password Help PLEEEASE !



Pete634
05-29-2007, 06:35 PM
Can anyone help me with this?

I've built a workbook with containing a number of userforms , which are accessed via a "Main Menu" userform which automatically loads on opening the workbook. A userform will always show on the screen, and a user can only get back to the main menu.

I've found some good code to disable the cancel button on the forms which I want to use to help achieve the above, but I will need to get back into my workbook at some point for further development. So, I put a commandbutton on the Main Menu titled "Developer" which, when pressed, will prompt for a password. Only when the correct password is entered will the Main Menu close, thereby allowing only me to access the workbook and the VBA code behind it.

Trouble is, I don't know how to code this last bit?

Any takers ?!

PS. I would post the workbook, but I'm still a VBA Newbie and you'll all laugh at my work (pages and pages of If statments!!!):blush

geekgirlau
05-29-2007, 07:06 PM
If "MyPassword" = InputBox("Enter the Developer password", "Password") Then
Unload Me
Else
MsgBox "That password is incorrect - go away!", vbExclamation, _
"Invalid Password"
End If

tccmdr
05-29-2007, 07:20 PM
Everyone has to start somewhere:clap:

I promise I won't laugh, and you never know, there are some great minds here that might help:yes

lucas
05-29-2007, 08:35 PM
You will probably need something like this too so they don't just close it using the X in the upper right hand corner of the form.
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
MsgBox "The X is disabled, please use the Close Command Button.", vbCritical
End If

End Sub

malik641
05-29-2007, 08:49 PM
Hi Pete634, and Welcome to VBAX! :hi:

In addition to geekgirlau's suggestion, you could probably place a boolean variable in the code to check if a developer opened the workbook. Like:

' For Window's login username:
If Environ("Username") = "Pete634" Then bDeveloper = True

' Or for Excel's App Username
If Application.UserName = "Peter" Then bDeveloper = True
And if bDeveloper is FALSE, then you could "hide" the Developer Button on the userform..so non-developers have no idea about it. And, obviously, if it's TRUE then you would Show the Developer button. That's probably what I'd do, anyway :)


PS. I would post the workbook, but I'm still a VBA Newbie and you'll all laugh at my work (pages and pages of If statments!!!):blush C'mon, I need a good laugh! :devil2: Aaaahh I'm just teasing! Like tccmdr said, everyone has to start somewhere. I, too, won't laugh at you...nor anybody here at VBAX I believe. So don't be shy :yes

malik641
05-29-2007, 08:49 PM
By the way, welcome to you too tccmdr!! :)

geekgirlau
05-29-2007, 09:12 PM
Often what I do is have an event such as this linked to something other than a button - for example, attach it to the double-click event on a logo or title text on your user form. That way it is always available, but not obvious to the average user.