Hi,
I am trying to set password protection on a combobox where there are only a few people who I want to be able to select their name to provide authorisation. I found the below code on a website and modified it slightly for my table (tbl_Approval) that contains two fields; Approver and Password. I can see how the code is supposed to work however I keep getting a syntax error (missing operator) in query expression on line: Set rs = CurrentDb.OpenRecordset(sql). Can anyone help? Thank you!
I am trying to set password protection on a combobox where there are only a few people who I want to be able to select their name to provide authorisation. I found the below code on a website and modified it slightly for my table (tbl_Approval) that contains two fields; Approver and Password. I can see how the code is supposed to work however I keep getting a syntax error (missing operator) in query expression on line: Set rs = CurrentDb.OpenRecordset(sql). Can anyone help? Thank you!
Code:
Private Sub Approved_By_Enter()
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 [tbl_Approval] " & "WHERE [Approver]= " & Me.Approved_By
Set rs = CurrentDb.OpenRecordset(sql)
recount = rs.RecordCount
'MsgBox "Record Count" & rs.Password
pwd = InputBox("Please enter password", "Secure")
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.Approved_By.SetFocus
' Start login process over again.
' Close the recordset.
rs.Close
Set rs = Nothing
Exit Sub
End If
End If
End Sub