Results 1 to 4 of 4

Thread: Compile error in VBA for Access- User defined type not defined

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    2

    Resolved Compile error in VBA for Access- User defined type not defined

    Hi I'm new to VBA and I'm just trying to create a connection object to the database and also a recordset object in order to add new records to the database. I am directly connected to the database and everytime I compile the following piece of code which is inside a Module it gives me a compile error for Dim dbCurrent As Database and dbMichael As Database. How do I get rid of it. Here is the code:

    Option Compare Database
    Option Explicit
    Function AddPlayer()


    Dim dbCurrent As Database
    Dim rstPlayers As Recordset
    Dim rstCards As Recordset
    Dim dbMichael As Database


    Set dbCurrent = DBEngine.Workspaces(0).Databases(0)

    'This will create a table-type recordset.
    Set rstPlayers = dbMichael.OpenRecordset("Players", "databases\Michael.mdb", DB_OPEN_DYNASET)
    'These will create a dynaset-type recordset.
    Set rstCards = dbMichael.OpenRecordset("Cards", "databases\Michael.mdb", DB_OPEN_DYNASET)

    rstPlayers.Move 4


    End Function


    Hopefully somebody can help- thanks in advance
    Last edited by catastrophic; Jan 12th, 2005 at 12:02 PM.

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Compile error in VBA for Access- User defined type not defined

    Have you added a reference for ADO to your project, if not then you need to !

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    2

    Re: Compile error in VBA for Access- User defined type not defined

    I thought that was just for Vb, I'm a bit confused between the two. Haven't done VBA before. I thought I was already connected to the database as the textboxes automatically filled up with records when I attached them to the table recordsource. So do I add an ADO object at design time and then create the connection through the Jet Engine?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Compile error in VBA for Access- User defined type not defined

    Since this is VBA inside an Access database you should have the reference for DAO
    - Microsoft DAO x.x Object Library. If not then add it. You can explicitly
    dimention your objects like so.

    VB Code:
    1. Option Compare Database
    2. Option Explicit
    3.  
    4. Function AddPlayer()
    5.  
    6.     Dim dbCurrent As DAO.Database
    7.     Dim rstPlayers As DAO.Recordset
    8.     Dim rstCards As DAO.Recordset
    9.     Dim dbMichael As DAO.Database
    10.  
    11.     Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
    12.  
    13.     'This will create a table-type recordset.
    14.     Set rstPlayers = dbMichael.OpenRecordset("Players", "databases\Michael.mdb", DB_OPEN_DYNASET)
    15.     'These will create a dynaset-type recordset.
    16.     Set rstCards = dbMichael.OpenRecordset("Cards", "databases\Michael.mdb", DB_OPEN_DYNASET)
    17.  
    18.     rstPlayers.Move 4
    19.  
    20. End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width