Solved Open Set Folder to Select File (1 Viewer)

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 20:25
Joined
Feb 5, 2019
Messages
293
Hi all,

I have the below code to select a file and save the location to a 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

How do I set the folder to dialog opens to so people cannot browse to the wrong folder?

At the moment it opens in the last used folder.

~Matt
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 20:25
Joined
Feb 5, 2019
Messages
293
Have you tried using the InitialFileName property?
Perfect.

Code:
    Dim f As Object
    Dim strDocumentFileName As String
    Dim varItem As Variant
    Dim strStartFolder As String
        strStartFolder = "\\sc-nas-01\XP-Share\Production & Shop Floor\Drawing Register\Cable Assemblys\" & Forms!frmProductBOM!ProductCode
    
    Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
        f.InitialFileName = strStartFolder
    If f.Show Then
        For Each varItem In f.SelectedItems
            strDocumentFileName = Dir(varItem)
            Me.txtDrawingFile = strDocumentFileName
        Next
    End If
    Set f = Nothing

It may not be elegant, but it works perfectly.

Thank you DBguy

~Matt
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:25
Joined
Oct 29, 2018
Messages
21,474
Hi Matt,

Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom