Hello All,
So I have created this combobox that requires the user to enter a password when selecting a value in my unbound combobox. If the password is incorrect then the combobox is cleared and is reset to the value it was before the update was attemped. Now I found code on getting this to work and it works great except for one minor flaw that I am trying to add to it. If the user goes to clear the combobox thus making the value null the Msgbox appears asking for the users password but fails each time because the null username does not exist. Im trying to make the proper if statement to check and see if the username selected from the combobox does not exist in the usertable then it just cancels the update statement.
I tried to explain as best that I could, sorry if this sounds confusing. Here is my code for the comboBox at the moment:
(btw I did not make this code I borrowed it from another forum)
Code:
Private Sub ComboAuth_AfterUpdate()
Dim pwd As String
Dim rs As Object, rstable As Object, count As Integer, counter As Integer
Dim sql As String, recount As Integer
sql = "SELECT * " & _
"FROM [dbo_User_Table] " & _
"WHERE [Username] = '" & Me.ComboAuth & "' "
Set rs = CurrentDb.OpenRecordset(sql)
recount = rs.RecordCount
'MsgBox "Record Count" & rs.Password
pwd = InputBox("Please enter password", "Password")
If pwd = rs.Password Then
rs.Close
Set rs = Nothing
Exit Sub ' return control to User on the form to allow another try
Else
If pwd <> rs.Password Then
' Here if incorrect Password for this Username.
MsgBox "That is not the correct password for" & Chr(13) & _
"that username. Please try Again.", vbExclamation, "Invalid Password"
'Me.ComboAuth.
If IsNull(ComboAuth.Text) Then
ComboAuth.Value = ""
Else: ComboAuth.Value = ComboAuth.OldValue
End If
Me.ComboAuth.SetFocus
' Start login process over again.
' Close the recordset.
rs.Close
Set rs = Nothing
Exit Sub
End If
End If
End Sub