Inputbox maybe?

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have a form with a command button that opens another form. What I would
like to do is when the user clicks on the button, as box appears asking to
enter the pasword. The user will all ready know the password. If the
password is entered wrong I would like the user to be given two choices. One
to re-enter the password, which if is correct will go ahead and open the
form. The second choice will be cancel which will return back to the
previous form. I have tried several variations of the inputbox, msgbox's and
am not able to make it work right. My form names are CustInfo, CustAdm.
Please help I need working code.

Thanks
 
Why?

Just set up Access' built in user-level security and only allow the
authorized people to open the form in the first place.

Do you really want someone to have to enter a password every single time
they open a special form? How many of these will you end up with as the
program grows and expands?

Use the built-in features to set your security.

Rick B


"John" <j> wrote in message I have a form with a command button that opens another form. What I would
like to do is when the user clicks on the button, as box appears asking to
enter the pasword. The user will all ready know the password. If the
password is entered wrong I would like the user to be given two choices. One
to re-enter the password, which if is correct will go ahead and open the
form. The second choice will be cancel which will return back to the
previous form. I have tried several variations of the inputbox, msgbox's and
am not able to make it work right. My form names are CustInfo, CustAdm.
Please help I need working code.

Thanks
 
Untested aircode. Using just the Input Box, this relies on the user actually
typing "Cancel" (or the correct password) to exit the loop.

Sub InputPassword(strPassword as string)
Dim bolOK as Boolean
Dim strResult as String

bolOK = False
Do
strResult = Trim(InputBox("Please enter the Password or Type CANCEL to
abort:","Enter Password"))

Select Case strResult
Case "CANCEL", "Cancel", "cancel")
' Code to exit back to Previous form
GoTo ExitSub ' *NOT* "Exit Do"
Case Else
If strResult = strPassword then
bolOK = True
Else
' Do nothing: code will loop and repeat the InputBox
End If
End Select
Loop While bolOK = False

' ......Code that allows access goes here
' (correct password must have been entered to have gotten here)

ExitSub
 
Back
Top