Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    show list of the databases (Access 2000)

    Is there any way to get the list of all databases present in the path
    "C:bestorebe.mdb"
    I mean to get the names of databases that i can find in this path. I have heard of a method called GetObjects but i am not sure what it means.
    Is it possible ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: show list of the databases (Access 2000)

    "C:bestorebe.mdb" is not a path, it is a path plus file name - at least, I hope you didn't name a folder "be.mdb", that would be very confusing.

    You can use the good old Dir function to find all databases in a folder:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Dim strPath As String
    Dim strFile As String

    ' Path, including trailing backslash
    strPath = "C:bestore"

    strFile = Dir(strPath & "*.mdb")

    Do While Not strFile = ""
    MsgBox "Found file " & strFile
    strFile = Dir
    Loop

    <img src=/w3timages/blueline.gif width=33% height=2>

    Note that Dir only returns the file name, without the path. So if you need to do something with the file, use strPath & strFile

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: show list of the databases (Access 2000)

    Thank you very much for your reply. I have taken your code and have made a function out of it:
    Public Function ListOfDB()

    Dim strPath As String
    Dim strFile As String

    ' Path, including trailing backslash
    strPath = "C:bestore"

    strFile = Dir(strPath & "*.mdb")

    Do While Not strFile = ""
    MsgBox "Found file " & strFile
    strFile = Dir
    Loop
    End Function

    Then i have put a control on the form with the OnClcik event ListOfDb.
    Then the function works, and on each click i receive the message FoundFile .....
    and thus i can see all the files, one by another in succession.
    So your code works. I need however to view these databases in the folder
    as a list and further i need to save this list and send this list to my boss.
    Is it possible ? And how can i make such a list from a code ?

    Best regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: show list of the databases (Access 2000)

    There are ways to print or store a directory listing without using Access, of course, but I assume this is meant as an exercise in using Access.

    I would create a table to store the file names. Let's say you create a table tblfDirList with a single text field FileName (make sure that its length is sufficient to store the longest database name).

    The following code uses DAO. You need to have a reference to the Microsoft DAO 3.6 Object Library (check / set it in Tools | Options... in the Visual Basic Editor.)

    Dim strPath As String
    Dim strFile As String
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL as String

    ' Reference to current database
    Set dbs = CurrentDb

    ' Clear existing entries from table
    strSQL = "DELETE * FROM tblDirList"
    dbs.Execute strSQL

    ' Open recordset
    Set rst = dbs.OpenRecordset("tblDirList", dbOpenDynaset)

    ' Path, including trailing backslash
    strPath = "C:bestore"

    strFile = Dir(strPath & "*.mdb")

    Do While Not strFile = ""
    ' Add new record
    rst.AddNew
    ' Put file name in FileName field
    rst!FileName = strFile
    ' Save record
    rst.Update
    ' On to the next
    strFile = Dir
    Loop

    ' Clean up
    rst.Close
    Set rst = Nothing
    Set dbs = Nothing

Posting Permissions

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