Password required button

C

Chad

Hello, I have this code behind a button and wanted to ask why it dont work?

Private Sub cmdLogin_Click()
Dim stDocName As String
Dim stLinkCriteria As String

If Me.txtPassword = "soggycashew" Then
stDocName = "frmUpdateEmployees"
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Form!frmSwitchboard.Visible = False 'Hides the switchboard

Else

Me.cmdHiddenButton.SetFocus
Me.cmdLogin.Visible = False
Me.txtPassword.Visible = False
Me.imgPassword.Visible = False
Me.cmdCancel.Visible = False
Me.imgIncorrectPassword.Visible = True
Me.TimerInterval = 4000
End If
End Sub
 
D

Daniel Pineault

Also, 'it dont work' doesn't give us much information to help you with. What
doesn't work? Do you get any errors? Have you put breaks in you code and
tested your variable values to ensure that they are populating as expected.
Give us more information.
 
C

Chad

Here is all I want it to do. I dont want to use the input box because im
using an image with just a txtPassword box to enter the pasword
"soggycashew". and i the password is correct I then want it to close the form
and open the form "frmUpdateEmployees" if the pasword in the txtpassword box
doesnt say soggycashew then I want to:
Me.cmdHiddenButton.SetFocus
Me.cmdLogin.Visible = False
Me.txtPassword.Visible = False
Me.imgPassword.Visible = False
Me.cmdCancel.Visible = False
Me.imgIncorrectPassword.Visible = True
Me.TimerInterval = 4000

And after the 4000 close the form. What I was getting was no errors but it
didnt matter what text I entered into the txtpassword because it always
opened the "frmUpdateEmployees" and ran:
Me.cmdHiddenButton.SetFocus
Me.cmdLogin.Visible = False
Me.txtPassword.Visible = False
Me.imgPassword.Visible = False
Me.cmdCancel.Visible = False
Me.imgIncorrectPassword.Visible = True
Me.TimerInterval = 4000

I just want if txtpassword = This then open frmUpdateEmployee

then if it doesnt then do this....
 
J

John Spencer

I don't see anything wrong with the code that you have posted.

Try inserting some message boxes or tracing the code to see what is
happening

Private Sub cmdLogin_Click()
Dim stDocName As String
Dim stLinkCriteria As String

'For testing purposes, check the password
MsgBox "Password is " & NZ(Me.txtPassword,"Null")

'You might make sure that your test doesn't fail if there
'is no password entered by forcing a string in the
'comparison statement
If Me.txtPassword & "" = "soggycashew" Then

stDocName = "frmUpdateEmployees"
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Form!frmSwitchboard.Visible = False 'Hides the switchboard

Else

Me.cmdHiddenButton.SetFocus
Me.cmdLogin.Visible = False
Me.txtPassword.Visible = False
Me.imgPassword.Visible = False
Me.cmdCancel.Visible = False
Me.imgIncorrectPassword.Visible = True
Me.TimerInterval = 4000
End If

End Sub

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top