Results 1 to 12 of 12
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    User-Defined Type Error?

    Hello Accessors!



    I am attempting to figure out what I am typing erroenously below. I keep getting 'Compile error: User-defined type not defined".

    Code:
    Dim rs As ADODB.RecordsetDim cmd As ADODB.Command
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
    Am I not typing this properly? Any help will be appreciated!

    Thanks!!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    sb:
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command

  3. #3
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    RuralGuy,

    Thank you for the help- But it does not help... all you did was add the sb: I am confused...

    However, here is a complete portion of the two codes:
    Private Sub Form_Load()
    Dim db As ADODB.Recordset
    Dim cmd As ADODB.Command
    Set db = New ADODB.Recordset
    Set cmd = New ADODB.Command

    'When the admin window opens this select statement will make certain areas availible to certain admin users

    cmd.ActiveConnection = CurrentProject.Connection
    cmd.CommandText = "SELECT AccessLevel FROM tblEmployee " _
    & "WHERE UserName = '" & Forms!frmmainmenu!txtUserName & "'"
    cmd.Execute
    db.Open cmd, , adOpenKeyset, adLockOptimistic
    'admins with a security level less than 4 will only have access to the functions in the box
    'on the right hand side of the form
    If db.Fields(0) < 4 Then
    Me.cmdAddEdit.Enabled = False
    Me.cmdActivity.Enabled = False
    Me.cmdByPass.Enabled = False
    Me.cmdDisByPass.Enabled = False
    Me.cmdShowDBWin.Enabled = False
    End If
    End Sub
    Private Sub cmdKick_Click()
    Dim db As ADODB.Recordset
    Dim cmd As ADODB.Command
    Set db = New ADODB.Recordset
    Set cmd = New ADODB.Command


    'This function will kick users out of the database so that if an admin needs to have Exclusive access to the database
    'THIS IS TO BE USED ONLY ON A NEED TO BASIS
    cmd.ActiveConnection = CurrentProject.Connection


    cmd.CommandText = "Select TimeOutID, ForceOff, TimeClose " _
    & "From tblTimeout " _
    & "Where TimeOutID = 1"
    cmd.Execute
    db.Open cmd, , adOpenKeyset, adLockOptimistic
    db.Fields(1) = -1
    db.Update
    Set cmd = Nothing

    End Sub
    Those two lines keep getting highlighted upon the error after I tried to execute these two codes...

    Why?!! Please help...

    Thanks!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm afraid I just do not have enough experience with ADO to be much help. I've always user DAO. Sorry.

  5. #5
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Thanks, RuralGuy...

    Anyone else who could help me....?

  6. #6
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Did you add the Microsoft ADO library?

    http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

  7. #7
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    lfpm,

    Yes, I did. Still no luck.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am not an ADO expert either but if I recall correctly keysets can only contain indexed fields.

    EDIT: Now that I think about it, using the find method requires an indexed field. Specifically which line is causing the error?

  9. #9
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    So the error raises on the Dim db line? To check dependency's: does the object explorer show you the Recordset class when viewing the ADODB library? As I'm no expert in ADO either I'm not sure, but AFAIK you start with an ADODB.Connection object and use methods of this object to open a recordset.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    hmmm, perhaps db is already used and available globally or in the module. Perhaps change db to adoR1 and adoR2 or something else unique.

  11. #11
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Do you have "Microsoft ActiveX Data Objects 6.1 Library" check in your reference libray?

    I have just did a quick test. I copy your code and uncheck the reference and it show the error "Compile error: User-defined type not defined". The error goes away once I checked that library.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Nice......

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  2. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  3. Replies: 4
    Last Post: 06-08-2012, 09:08 AM
  4. Error:User-Define type not defined
    By A S MANN in forum Programming
    Replies: 8
    Last Post: 11-05-2011, 04:31 AM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums