Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

 

The following vba code shows how to create a file dialog in Microsoft Access and evaluate the selected files.

 

Filedialog in MS Access

The file dialog will appear as shown here. You can select files after opening and accept them with the Open button.

 

 

And the selected files

 

vba

The file dialog is created as Application.FileDialog and you can set the button as text, the specification of the selected file extensions and the base directory with which to start.

 

    '--< Import-Dialog >--

    Dim objFiledialog As FileDialog

    Set objFiledialog = Application.FileDialog(msoFileDialogFilePicker)

    objFiledialog.AllowMultiSelect = True

    objFiledialog.ButtonName = "Import Images"

    objFiledialog.Filters.Add "Images Photos", "*.jpg;*.png;*.tiff;*.gif"

    objFiledialog.Title = "Fotos auswählen.."

    objFiledialog.InitialView = msoFileDialogViewTiles

    'objFiledialog.InitialFileName = const_Path_Photos_Default

    objFiledialog.AllowMultiSelect = True

    If Not objFiledialog.Show() = True Then

        Exit Sub

    End If

    '--< Import-Dialog >--

 

 

The selected files can be run through as SelectedItems. The file path is returned as string.

For iFile = 1 To objFiledialog.SelectedItems.Count

        '------< Loop.Item  >------

        DoEvents

 

        '< get selection >

        sFilename = objFiledialog.SelectedItems(iFile)

        '</ get selection >

 

        sFiles = sFiles & vbCrLf & sFilename

    Next

 

 

 

Recommendation:

All you should do in the vba file in References is the Office Object Library. But that's not a must.

 

Public Sub fg_Bilder_Holen()

    '--------------------< fg_Bilder_Holen() >--------------------

    '--< Import-Dialog >--

    Dim objFiledialog As FileDialog

    Set objFiledialog = Application.FileDialog(msoFileDialogFilePicker)

    objFiledialog.AllowMultiSelect = True

    objFiledialog.ButtonName = "Import Images"

    objFiledialog.Filters.Add "Images Photos", "*.jpg;*.png;*.tiff;*.gif"

    objFiledialog.Title = "Fotos auswählen.."

    objFiledialog.InitialView = msoFileDialogViewTiles

    'objFiledialog.InitialFileName = const_Path_Photos_Default

    objFiledialog.AllowMultiSelect = True

    If Not objFiledialog.Show() = True Then

        Exit Sub

    End If

    '--< Import-Dialog >--

 

 

    '-< check >-

    '</ Ordner ist leer >

    If objFiledialog.SelectedItems().Count = 0 Then

        Exit Sub

    End If

    '</ Ordner ist leer >

    '-</ check >-

 

    Dim sFiles As String

 

    Dim iFile As Integer

    Dim sFilename As String

    For iFile = 1 To objFiledialog.SelectedItems.Count

        '------< Loop.Item  >------

        DoEvents

 

        '< get selection >

        sFilename = objFiledialog.SelectedItems(iFile)

        '</ get selection >

 

        sFiles = sFiles & vbCrLf & sFilename

    Next

 

    '< show result >

    MsgBox sFiles, vbInformation, "Selected Files"

    '</ show result >

 

    '--------------------</ fg_Bilder_Holen() >--------------------

End Sub

 

Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de