Results 1 to 4 of 4

Thread: access vba

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    257

    access vba

    I am brand new to vba for access and I tried running some examples from a book I read, but the objects I am referencing are not being recognized (like dim db as database). Do I have to reference or import anything first? The code that doesn't work is as follows:

    VB Code:
    1. Option Compare Database
    2.  
    3. Sub exaCreateQuery()
    4.  
    5. Dim db As database
    6. Dim rs As Recordset
    7. Set db = CurrentDb
    8.  
    9.  
    10. End Sub

    produces the error: user defined type not defined

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    You may not have enabled the VBA references.

    Go to VB Editor and look at the list under Tolls/References. Check any Object Library that seems appropriate.

    You may need to re-run the setup disk/custom setup to add Visual Basic items. They are not always installed by default.
    Regards
    BrianB
    -------------------------------

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    The main way to access databases is by using ADO (ActiveX Data Objects). It may be worth your while searching the net for a quick tutorial on getting started with this.

    As above, you can add the ADO libraries / code which you can call on, by going to the tools menu > references opption & checking the box next to the "Microsoft Activex Data Objects x.x object library" entry.

    I believe the code you are using above from this book is teaching you how to code using the DAO object libraries. This can also be accessed by adding a reference (as above) to the "Microsoft Data Access Object x.0 Object Library", & adding this in will make the above code work & should present intellisense in your code.

    I would recommend looking up a tutorial on ADO first as DAO is an older and less efficient technology used back in the days of office 97 etc.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    257

    RESOLVED

    Thank you, that is what I suspected.

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