Using FileDialog property to open and display FileName in a textbox and in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajtovi007
    New Member
    • Jul 2009
    • 2

    Using FileDialog property to open and display FileName in a textbox and in a table

    Hi,
    I've found code in thread:
    Using FileDialog property to open File and display FileName in a textbox
    but:
    1. I do not know how to add it in to ACCESS 2003 database.
    2. I have fields in database with FirstName, LastName and IDnumber. How to Create folder named "LastName FirstName IDnumber" from ACCESS 2003 (on a click on a batton)?
    3. And, additionaly, is it possible to add all files from this folder (folder created and opened in previous step) on a list on the form (or as labels-hyperlinks on current form)?

    Thanks in advance
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by sajtovi007
    Hi,
    I've found code in thread:
    Using FileDialog property to open File and display FileName in a textbox
    but:
    1. I do not know how to add it in to ACCESS 2003 database.
    2. I have fields in database with FirstName, LastName and IDnumber. How to Create folder named "LastName FirstName IDnumber" from ACCESS 2003 (on a click on a batton)?
    3. And, additionaly, is it possible to add all files from this folder (folder created and opened in previous step) on a list on the form (or as labels-hyperlinks on current form)?

    Thanks in advance
    Hi

    To get you started the following code can be moded to your database to create a new directiory
    Code:
    Sub CreateDirectory()
        Dim rs As New ADODB.Recordset
        Dim SQL As String
        
        SQL = "SELECT FName, SName, ID FROM tblContacts WHERE ID = 2"
        rs.Open SQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
        
        MkDir "C:\" & rs("FName") & " " & rs("SName") & " ID is " & rs("ID")
        
        rs.Close
        Set rs = Nothing
    End Sub
    and to obtain a list of selected files in a gived directory some thing like this perhapse
    Code:
    Sub ListFiles()
        Dim dlgOpen As FileDialog
        Dim ThisFilePath As Variant
        Dim FileName As String
        Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
        
        With dlgOpen
            .AllowMultiSelect = True
            .Filters.Add "Excel Files", "*.xls", 1
            If .Show = -1 Then
                For Each ThisFilePath In .SelectedItems
                    FileName = Mid(ThisFilePath, InStrRev(ThisFilePath, "\") + 1)
                    MsgBox FileName
                Next ThisFilePath
            End If
        End With
    End Sub
    This assumes you want to select the directory manualy (if not i don't know how you will now wich directories exist). A plausible alternative is to use the DIR function (see Access help or post back if you need a pointer or two on that).

    There is another alternative using the FileSystemObjec t (this will need a reference to the 'Microsoft Scripting Runtime' Library) but that is even more stuff to learn, not a bad think, but you can't learn it ALL at once!!.

    Hope this helps


    MTB

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by sajtovi007
      Hi,
      I've found code in thread:
      Using FileDialog property to open File and display FileName in a textbox
      but:
      1. I do not know how to add it in to ACCESS 2003 database.
      2. I have fields in database with FirstName, LastName and IDnumber. How to Create folder named "LastName FirstName IDnumber" from ACCESS 2003 (on a click on a batton)?
      3. And, additionaly, is it possible to add all files from this folder (folder created and opened in previous step) on a list on the form (or as labels-hyperlinks on current form)?

      Thanks in advance
      Download the Attachment to see how to select a File from the File Dialog, then to display its Absolute Path in a Text Box.

      Comment

      Working...