browse for a file (1 Viewer)

ilanray

Member
Local time
Today, 08:46
Joined
Jan 3, 2023
Messages
116
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
 

GaP42

Active member
Local time
Today, 15:46
Joined
Apr 27, 2020
Messages
338
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
 

June7

AWF VIP
Local time
Yesterday, 21:46
Joined
Mar 9, 2014
Messages
5,471
Since you allow only one selection, don't need to loop.


Code:
    If f.Show Then
        Me.txtDrawingFile = f.SelectedItems(1)
    End If
 

ilanray

Member
Local time
Today, 08:46
Joined
Jan 3, 2023
Messages
116
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:46
Joined
Oct 29, 2018
Messages
21,473
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.
 

ilanray

Member
Local time
Today, 08:46
Joined
Jan 3, 2023
Messages
116
if you are not using Hyperlink data type what is the best way to work with in VBA?
 

June7

AWF VIP
Local time
Yesterday, 21:46
Joined
Mar 9, 2014
Messages
5,471
I just save path in a text field and build Hyperlink when needed. Did you review links I posted?
 

ilanray

Member
Local time
Today, 08:46
Joined
Jan 3, 2023
Messages
116
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
 

cheekybuddha

AWF VIP
Local time
Today, 06:46
Joined
Jul 21, 2014
Messages
2,280
Perhaps:
Code:
' ...
        For Each varItem In f.SelectedItems
            strDocumentFileName = Mid(varItem, InStrRev(varItem "\") + 1)
            Me.txtDrawingFile = strDocumentFileName
        Next
' ...
 

mike60smart

Registered User.
Local time
Today, 06:46
Joined
Aug 6, 2017
Messages
1,905
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

  • BIMDocMan3.zip
    37 KB · Views: 91

Users who are viewing this thread

Top Bottom