Little help if you don't mind

Summit

Registered User.
Local time
Today, 14:57
Joined
Apr 26, 2012
Messages
22
I just started experimenting with access this year and am still trying to wrap my head around coding so I could use a little help if you don't mind.

In my database I have the navigation bar and the ribbon hidden so it looks a little more user friendly for those who use it. I have an administrative log in section where I can log in and make the ribbon and navigation bar reappear so I can make back end data changes.

I am currently using the below code for the log in, but of course the password is viable when I type it in. I have created a form so that I can type in the password with the letters hidden(***) into a text box, but I can't figure out how to code the text box for the entered password to work the way I want to. I also don't know which event to use.

I want the password, if correct to
open form Menuboard Admin
close form Enter Password

If incorrect, just deny access to the page, which is how the below code handles it.

Any help would be appreciated!

Private Sub Command20_Click()
Dim PassWord As String
strPassword = "12345"
If InputBox("Enter Administrator Password") = strPassword Then
DoCmd.OpenForm "Menuboard Admin"
DoCmd.Close acForm, "Menuboard Main Start"
Else
MsgBox ("You're not authorized for Administrator access.")
End If
End Sub
 
Have you tried an input mask? If you go to the properties for InputBox, under the Data tab is a property called InputMask that controls what kinds of characters users are allowed to type in a box. Set it to Password and it will display asterisks as you type but still retain the value.
 
You'll need a textbox, name it txtPassword.

Then, on click of a button, or even on lost focus of the textbox, run the below code

Code:
Dim PassWord As String
strPassword = "12345"
If me.txtPassword = strPassword Then
  DoCmd.OpenForm "Menuboard Admin"
  DoCmd.Close acForm, "Menuboard Main Start"
Else
  MsgBox ("You're not authorized for Administrator access.")
End If
 
You'll need a textbox, name it txtPassword.

Then, on click of a button, or even on lost focus of the textbox, run the below code

Code:
Dim PassWord As String
strPassword = "12345"
If me.txtPassword = strPassword Then
  DoCmd.OpenForm "Menuboard Admin"
  DoCmd.Close acForm, "Menuboard Main Start"
Else
  MsgBox ("You're not authorized for Administrator access.")
End If

Thank you very much, that code is working almost perfectly. The close form command is not working however (the form to close is actually named Menuboard Password). I'm getting error code 2585. Also, I put the code on event lost focus

Private Sub txtPassword_LostFocus()
Dim PassWord As String
strPassword = "12345"
If Me.txtPassword = strPassword Then
DoCmd.OpenForm "Menuboard Admin"
DoCmd.Close acForm, "Menuboard Password"
Else
MsgBox ("You're not authorized for Administrator access.")
End If
End Sub
 
Last edited:
Forgot I had to close another form when the password is correct so that is reflected in the code below. Also I changed Menuboard Password to Menuboard Login. I am still unable to close "Menuboard Login.".

Private Sub txtPassword_LostFocus()
Dim PassWord As String
strPassword = "12345"
If Me.txtPassword = strPassword Then
DoCmd.OpenForm "Menuboard Admin"
DoCmd.Close acForm, "Menuboard Main Start"
DoCmd.Close acForm, "Menuboard Login"
Else
MsgBox ("You're not authorized for Administrator access.")
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom