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

    Finding existing databases (Access 2000)

    I have a very precious code suggested to me by the Moderators of the present forum. It checks the path "C:BE" on loading the form.The function works excellent. I would like to extend the function and get 2 more paths:
    "C:BEstoreBE"
    and also, anything that is on the desktop.About the desktop, i cannot find it,is there
    any general path to that?
    I have tried to repeat the code by adding the
    Me.txtFolder = "C:BEstoreBE"

    But the data are received only for the firsr case.Is it possible to obtain for the

    underlying table the three records ? The table LsitDB has an ListID as an autonumber



    Private Sub Form_Load()
    Me.txtFolder = "C:BE"
    GetDBList Me.txtFolder
    DoCmd.RunCommand acCmdSaveRecord
    End Sub



    Private Sub GetDBList(ByRef strPath As String)
    Dim CheckFile As String
    Dim strList As String
    CheckFile = Dir(strPath & "/*.mdb")
    Do Until CheckFile = ""
    strList = strList & vbCrLf & CheckFile
    CheckFile = Dir
    Loop
    Me.txtDatabaseList = Mid$(strList, 3)
    End Sub
    Private Sub Form_Load()
    Me.txtFolder = "C:BE"
    GetDBList Me.txtFolder
    DoCmd.RunCommand acCmdSaveRecord
    End Sub

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

    Re: Finding existing databases (Access 2000)

    Here is code using Windows API calls to retrieve the user's desktop folder <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

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

    Public Const CSIDL_DESKTOP = &H0

    Private Type ######EMID
    cb As Long
    abID As Byte
    End Type

    Private Type ITEMIDLIST
    mkid As ######EMID
    End Type

    Private Declare Function SHGetSpecialFolderLocation _
    Lib "shell32.dll" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long

    Private Declare Function SHGetPathFromIDList _
    Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
    (ByVal pidl As Long, ByVal pszPath As String) As Long

    Public Function GetSpecialFolder(CSIDL As Long) As String
    Dim r As Long
    Dim IDL As ITEMIDLIST
    Dim Path As String
    'Get the special folder
    r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    If r = 0 Then
    'Create a buffer
    Path = Space$(512)
    'Get the path from the IDList
    r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
    'Remove the unnecessary chr$(0)'s
    GetSpecialFolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
    Exit Function
    End If
    GetSpecialFolder = ""
    End Function

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

    To get the desktop, use GetSpecialFolder(CSIDL_DESKTOP)

    Here is the On Load event; it creates 3 records.

    Private Sub Form_Load()
    Me.txtFolder = "C:BE"
    GetDBList Me.txtFolder
    ' Move to new record
    RunCommand acCmdRecordsGoToNew
    Me.txtFolder = "F:AccessSamples"
    GetDBList Me.txtFolder
    ' Move to new record again
    RunCommand acCmdRecordsGoToNew
    Me.txtFolder = GetSpecialFolder(CSIDL_DESKTOP)
    GetDBList Me.txtFolder
    End Sub

Posting Permissions

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