Log in

View Full Version : Recordset Error: Compile Error: User-defined type not defined



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

bbtl
09-08-2015, 08:54 AM
Any help would be greatly appreciated

mancubus
09-09-2015, 06:19 AM
welcome to the forum.

i am no Access expert.

Google gave me this to passwprd protect a db:
https://scottgem.wordpress.com/2010/01/12/creating-login-security-using-access-vba/

bbtl
09-09-2015, 08:36 AM
Thank you mancubus, I will try it out and hopefully this will be a better option. However, do you know why "recordset" is not showing up in my library or "database"? I have googled for hours and cannot find out why it will not show up as an option. I appreciate the help.

bbtl
09-09-2015, 08:37 AM
I have tried adding other VBA references to the library and also try putting DAO.Recordset or ADO.Recordset and it still doesn't recognize it.

Kyle234
09-09-2015, 09:06 AM
Have you added a reference to MS Active Data Objects?

bbtl
09-09-2015, 11:23 AM
Hopefully I attached the document correctly but the document is a snapshot of what I currently have and what MS options there are. I have tried different variations but either get error messages or the "recordset" variable type is still not an option. I should also mention that I am using Access 2013-if that matters.

jonh
09-09-2015, 11:39 AM
On line 3, change * to &

bbtl
09-09-2015, 01:45 PM
Now I am going to sound like a moron but I found that if I open a new blank database and create a new module then "Recordset" appears in the option. So it might be the way my database is design or something.