Results 1 to 14 of 14

Thread: Database Conectivity

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5

    Angry

    This is a very simple question yet I don't seem to be able to work it out. I have conected to a database using an adodb conection. All I want to do is to be able to display the table names in that database on a form.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What sort of database are you using?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5
    Access 2000 using Jet 4.0

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not sure if this is totally legal, but it works on Access 2000
    Code:
    Dim x As New Recordset
    x.Open "SELECT [Name] FROM MSysObjects WHERE [Type]=4;", CurrentProject.Connection, adOpenDynamic, adLockReadOnly
    x.MoveFirst
    While Not x.EOF
        Debug.Print x!Name
        x.MoveNext
    Wend
    x.Close
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5
    Thanks for that, have just tried it but I'm getting an error.

    Record(s) can't be read; no permission on 'MSysObjects'

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Bugger

    The reason that worked for me was probably because I did that inside Access, due to the fact that I haven't managed to get round to reinstalling VB yet What user are you logging on as?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5
    I'm logged on as Admin

    It's a real pain you would have thought there would be some straight forward way of seeing the table names.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I couldn't find anything in the documentation about it *grr* *grr*

    Most RDBMSs have a SQL statement that returns a recordset with the table names in, equivalent to MySQL's "SHOW TABLES;" statement.

    I expect there *is* a method...they're just keeping quiet about it Maybe a look on the MS Knowledge Base might be productive.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Try this:

    Add a listbox called "lstTables" to a form. Add a reference to Microsoft DAO 3.6 Object Library (or whichever version you have the latest of) and paste this code into the Form_Load event.
    Code:
    Dim dbTest As Database
    Set dbTest = OpenDatabase("MyDB.mdb", False, False, ";pwd=" & "MyPassword")
    Dim tblObj As DAO.TableDef
    Dim intI As Integer
    
    lstTables.Clear
    For Each tblObj In dbTest.TableDefs
        If UCase(Left(tblObj.Name, 4)) <> "MSYS" Then
            lstTables.AddItem tblObj.Name
        End If
    Next
    
    dbTest.Close

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Oh well...I was trying to avoid DAO but it seems there's no way round it It's Access 2000 so it needs to be 3.6 or later.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Originally posted by parksie
    Oh well...I was trying to avoid DAO but it seems there's no way round it.
    It works, I use it. Nuff said.
    It's Access 2000 so it needs to be 3.6 or later.
    He might have the pre-release 3.7 (you never know, could happen).

  12. #12

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5
    I've just tried that and it works fine.

    Thanks very much for everybodies help.

  13. #13
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Good ol' DAO wins round one

  14. #14
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Post Didn't anyone write about ADOX?

    HI there,
    I don't subscribe to the view abotu using DAO. You could use ADOX just as effectively.

    Cheers!
    Abhijit
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

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