bbtl
09-08-2015, 08:51 AM
Sorry I am new to VBA and I cannot figure out why there is a compile error on the two variables bold below. Any time I type "Dim as R_" recordset does not show up as on object option. In short, I am trying to apply a password on forms and found this VBA code online. I have followed the steps but cannot figure out this error.
Private Sub Form_Open(Cancel As Integer)
id = 1
Set Me.Recordset = CurrentDb.OpenRecordset(CurrentDb.OpenRecordset("select filterdetail from filters where id=" * id)(0))
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As Recordset
Dim db As Database
On Error GoTo Error_Handler
' Check to see if the user is passing in the Password.
Hold = InputBox("Please Enter Your Password", "Enter Password")
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password info. Please Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the key in
' the table; if there is not a match, stop the form
' from opening.
If Not (rs![KeyCode] = KeyCode(CStr(Hold))) Then
MsgBox "Sorry you entered the wrong password. " & _
"Please try again.", vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub
Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
Exit Sub
End Sub
Private Sub Form_Open(Cancel As Integer)
id = 1
Set Me.Recordset = CurrentDb.OpenRecordset(CurrentDb.OpenRecordset("select filterdetail from filters where id=" * id)(0))
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As Recordset
Dim db As Database
On Error GoTo Error_Handler
' Check to see if the user is passing in the Password.
Hold = InputBox("Please Enter Your Password", "Enter Password")
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password info. Please Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the key in
' the table; if there is not a match, stop the form
' from opening.
If Not (rs![KeyCode] = KeyCode(CStr(Hold))) Then
MsgBox "Sorry you entered the wrong password. " & _
"Please try again.", vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub
Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
Exit Sub
End Sub