How to get table names from ms access(mdb file) by using odbclibrary.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JS

    How to get table names from ms access(mdb file) by using odbclibrary.


    Hi.

    I am writing a c++ program get the data from mdb file using odbc
    library.
    By the way, I couldn't get table list from mdb file.
    i goolgled it up little bit, what i found is only using the ADO(or OLE
    i'm not sure) library and
    "SELECT Name FROM MSysObjects WHERE Type In (1,4,6) AND Left([Name],
    4)<>"MSYS" this query.
    i already wrote a lot of part of this program so i don't want to
    switch database library.
    And the query gives "no read permission on 'MSysObjects' " error
    message.

    If you know how to get the table list from a mdb file by using odbc
    library, please share your experience.

    thank you.

  • Albert D. Kallal

    #2
    Re: How to get table names from ms access(mdb file) by using odbc library.

    If you using odbc to a mdb file, then you MUST have jet installed, and
    THEREFORE you MUST also have dao installed on your machine (in fact, out of
    the box, windows xp, server 2003, vista etc DOES HAVE the jet database
    engine installed by default (thus you don't need to install anything on a
    windows computer to read mdb files.

    here is a windows (vbs) script that displays all tables...you can use late
    binding in your project, and you should little trouble getting a list of
    tables using the following idea.

    Set dbeng = CreateObject("D AO.DBEngine.36" )
    strMdbFile = "C:\Documen ts and Settings\Lawren ce\My
    Documents\Acces s\ScriptExample \MultiSelect.md b"
    Set db = dbeng.OpenDatab ase(strMdbFile)
    for each table in db.tabledefs
    msgbox table.name
    next

    The above is not a vba script. Paste the above into a text document, and
    then re-name the extension as .vbs. If you double click on this file...you
    see it list the tables in the given mdb file..

    So there is a table collection available after you open the mdb file as per
    above...


    --
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada
    pleaseNOOSpamKa llal@msn.com


    Comment

    • banem2@gmail.com

      #3
      Re: How to get table names from ms access(mdb file) by using odbclibrary.

      On Aug 9, 3:04 am, "Albert D. Kallal" <PleaseNOOOsPAM mkal...@msn.com >
      wrote:
      If you using odbc to a mdb file, then you MUST have jet installed, and
      THEREFORE you MUST also have dao installed on your machine (in fact, out of
      the box, windows xp, server 2003, vista etc DOES HAVE the jet database
      engine installed by default (thus you don't need to install anything on a
      windows computer to read mdb files.
      >
      here is a windows (vbs) script that displays all tables...you can use late
      binding in your project, and you should little trouble getting a list of
      tables using the following idea.
      >
      Set dbeng = CreateObject("D AO.DBEngine.36" )
      strMdbFile = "C:\Documen ts and Settings\Lawren ce\My
      Documents\Acces s\ScriptExample \MultiSelect.md b"
      Set db = dbeng.OpenDatab ase(strMdbFile)
      for each table in db.tabledefs
         msgbox table.name
      next
      >
      The above is not a vba script. Paste the above into a text document, and
      then re-name the extension as .vbs. If you double click on this file...you
      see it list the tables in the given mdb file..
      >
      So there is a table collection available after you open the mdb file as per
      above...
      >
      --
      Albert D. Kallal    (Access MVP)
      Edmonton, Alberta Canada
      pleaseNOOSpamKa l...@msn.com

      "Paste the above into a text document, and
      then re-name the extension as .vbs."

      Or save file in Notepad with quotes, like:

      "TableNames.VBS " (including quotes)

      will save file without .TXT extension. :)

      Regards,
      Branislav Mihaljev
      Microsoft Access MVP

      Comment

      Working...