browse for a file

ilanray

Member
Local time
Today, 18:01
Joined
Jan 3, 2023
Messages
129
Hi
I would like to create a form with upload file option.
the uploda include browse option. everytime I click on the browse it should open a dialog box.
which mean it should add the record to the table and for that I create a table with id and links fields

I found a code below that open a dialog box.
how do I store the folder and and the file name on my table

Code:
Dim f As Object
    Dim strDocumentFileName As String
    Dim varItem As Variant

    Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
    If f.Show Then
        For Each varItem In f.SelectedItems
            strDocumentFileName = Dir(varItem)
            Me.txtDrawingFile = strDocumentFileName
        Next
    End If
    Set f = Nothing
 
Your me.textDrawingFile statement writes the name of the combined path-filename into txtdrawingfile field? - does it not?.

I use this to write the LocationLink field.

Code:
If (f.Show = True) Then

    For Each fname In f.SelectedItems
          Me.LocationLink.Value = fname 
    Next
        
Else
    MsgBox "No File Chosen"
End If
 
Since you allow only one selection, don't need to loop.


Code:
    If f.Show Then
        Me.txtDrawingFile = f.SelectedItems(1)
    End If
 
Great the path and the file name is working but when the textbox show me the link it looks like I can click on it since the textbox bind to hyperlink in the table. But when I am trying to click it doesn't do anything for example after I load 1.xlsx to the textbox I can see c:\1.xlsx but when I click on it it doesn't do anything
 
Hi. Since you're browsing to a file anyway, try dragging the file you're selecting to the hyperlink textbox on the form and see what happens.
 
if you are not using Hyperlink data type what is the best way to work with in VBA?
 
I just save path in a text field and build Hyperlink when needed. Did you review links I posted?
 
Hi Again
I still don't get it gow can I display or seperate just the file name for display purpose

Code:
Dim f As Object
    Dim strDocumentFileName As String
    Dim varItem As Variant

    Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
    If f.Show Then
        For Each varItem In f.SelectedItems
            strDocumentFileName = Dir(varItem)
            Me.txtDrawingFile = strDocumentFileName
        Next
    End If
    Set f = Nothing
 
Perhaps:
Code:
' ...
        For Each varItem In f.SelectedItems
            strDocumentFileName = Mid(varItem, InStrRev(varItem "\") + 1)
            Me.txtDrawingFile = strDocumentFileName
        Next
' ...
 
Hi Again
I still don't get it gow can I display or seperate just the file name for display purpose

Code:
Dim f As Object
    Dim strDocumentFileName As String
    Dim varItem As Variant

    Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
    If f.Show Then
        For Each varItem In f.SelectedItems
            strDocumentFileName = Dir(varItem)
            Me.txtDrawingFile = strDocumentFileName
        Next
    End If
    Set f = Nothing
This is an example
 

Attachments

Users who are viewing this thread

Back
Top Bottom