Hello everyone,
I've been trying to creat a login screen in access but its giving me some trouble. I already designed the form but apparently my code is not working. I tried this :
Code:
Dim strUserName As String
Dim strPassword As String
Dim stDocName As String
Dim stLinkCriteria As String
txtPassword.SetFocus
If IsNull(txtPassword) Then
MsgBox "Missing password"
Exit Sub
Else
strPassword = txtPassword
End If
txtUserName.SetFocus
If IsNull(txtUserName) Then
MsgBox "Missing name"
Exit Sub
Else
strUserName = txtUserName
End If
txtPassword.SetFocus
If txtPassword <> "p" Then
MsgBox "Wrong password"
Exit Sub
Else
stDocName = "frmSwitchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.Visible = False
txtPassword.Text = Clear
End If
txtUserName.SetFocus
If txtUserName <> "d" Then
MsgBox "Wrong UserName"
Exit Sub
Else
stDocName = "frmSwitchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.Visible = False
txtUserName.Text = Clear
End If
Exit_cmdOk_Click:
Exit Sub
Err_cmdOk_Click:
MsgBox Err.Description
Resume Exit_cmdOk_Click
End Sub
My problem is when i enter a password or a user name other than the ones specified by the code it displays the message then opens the switchbard anyways. I want it to display the message then go back to the login screen (with the previously entered values erased).