So, I was looking for a way to prevent my users from accessing one of my forms. I found a video from a couple of years ago, here is the link - https://www.youtube.com/watch?v=bPvzneN1jyg&t=1s
I got most of it to work but for some reason when I enter the wrong user name or password, or leave the boxes blank, I get a run-time error, type-mismatch. I've tried this a couple of times over the last couple of days thinking that maybe I may of miss typed something. The author of the video does not provide a URL to his website that I can find so I am trying to re-type it from the video.
I can get it to work if I use the correct user name and password, so I know that much of it works and the quit button works fine, also.
Below is the code, maybe someone can see what is missing. Funny, the author shows it works on his computer and goes back to the VBA and it looks exactly like mine so I cannot see how his is working but mine is not but this is not the first time that I may have missed something.
Option Compare Database
Dim passok As Boolean
Dim pass As String
Private Sub cmdOK_Click()
On Error GoTo cmdOK
Dim UserN As String
Dim clogin As String
Dim stDocName As String
Dim stLinkCriteria As String
pass = DLookup("[password]", "login", "[UserName]= '" & cboUserName & "'")
If Passwords <> pass Or IsNull(Passwords) Then
MsgBox "Wrong Password", vbCrLf & "Retry!!", vbCritical, "User Login Pro!!"
Exit Sub
End If
passok = True
DoCmd.Close
stDocName = "SWITCHBOARD"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
cmdOK:
MsgBox "User doesn't exist!", vbCrLf & Err.Description, vbExclamation, "User Login Pro!!"
End Sub
Private Sub cmdQuit_Click()
On Error GoTo err_cmdQuit_click
Dim resp As String
resp = MsgBox("Do you want to quit?!", vbYesNo, "User Login Pro!")
If resp = vbNo Then
Exit Sub
End If
DoCmd.Quit
exit_cmdQuit_click:
Exit Sub
err_cmdQuit_click:
MsgBox Err.Description, vbExclamation, "User Login Pro!!"
Resume exit_cmdQuit_click
End Sub
Additionally, while watching his video and trying to make this work, I got to thinking, what keeps other users from opening the login table and changing the passwords or adding someone else that should not have access? Any help will be appreciated.