Results 1 to 7 of 7

Thread: How to populate the tables in Access?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to populate the tables in Access?

    I would like to know how to populate the tables in Access? I have the sample code below but it use DAO.. I want to use ADODB connection, so What reference I can use to populate the access tables into my combo box?

    Code:
        Dim db As Database
        Dim wrk As Workspace
        Dim tdf As TableDef
        For Each tdf In db.TableDefs
        If Left(tdf.Name, 4) <> "MSys" And tdf.Name <> "pass" And tdf.Name <> "KERJA" Then _
           cboTable.AddItem tdf.Name
        Next tdf

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: How to populate the tables in Access?

    Code:
    SELECT Name 
    FROM MSysObjects 
    WHERE (Name Not Like "MSys*") 
    AND (Type In (1,4,6)) 
    ORDER BY Name

    (Type 1 is tables in the MDB file, 4 are tables linked through ODBC, and 6
    are other linked tables)

    Found Solution At:

    http://www.microsoft.com/communities...&cr=&sloc=&p=1
    thanks
    amrita

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to populate the tables in Access?

    The reference would be the ActiveX Data Objects Library.

    I suspect you already have that in your project, correct?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to populate the tables in Access?

    Yes, I already have it. Microsoft Active X Data Object 2.7 Library.

    But when I uncheck this reference Microsoft DAO 3.6 Object Library, This cannot work "Dim db As Database" used it. Is there any reference I can replace DAO so that I can populate the tables into my combo box.. I don't want to use DAO anymore to populate the tables into my combo box.


    Code:
        Dim db As Database
        Dim wrk As Workspace
        Dim tdf As TableDef
        For Each tdf In db.TableDefs
        If Left(tdf.Name, 4) <> "MSys" And tdf.Name <> "pass" And tdf.Name <> "KERJA" Then _
           cboTable.AddItem tdf.Name
        Next tdf

  5. #5
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: How to populate the tables in Access?

    Check some good tutorials on ADO with VB.

    Then connect to your Access Db with ADO connection and exceute the query provided by me in a previous post to this thread.

    You can use the record set object to populate the combo.
    thanks
    amrita

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to populate the tables in Access?

    Quote Originally Posted by matrik02
    But when I uncheck this reference Microsoft DAO 3.6 Object Library, This cannot work "Dim db As Database" used it.
    Of course it won't work. You removed the reference which declared Database as a valid variable type.

    None of that code, as written, will work.

    It has to be rewritten using ADO.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to populate the tables in Access?

    If this is only to work with .mdb files, amrita's advice is the easiest solution - just open a recordset (which you have done before) using that SQL statement.

    If it is to work with other database systems too (perhaps SQL Server and Oracle), I would recommend using the connections .OpenSchema method as the source for the recordset. You can see an example of this in the code of my "reserved words checker", link in my signature.

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