Hi all in access forums.net
Good day. I am stuck here with this coding. I am using this function plus this code behind a forms button. The form has just only this control. When I click the button it opens mso filedialog picker and I select the files I want to import. It Imports One of the selected files nicely.
Can somebody please see this code and help me to import all selected files not just one file. Hope this is possible. Here is the function at the top of the button in code window and the code behind the single button on form.
Thanks
Please see the code
Code:
Option Compare Database
Function FileNameNoExt(strPath As String) As String
' get file name without extension
'x = FileNameNoExt("C:\Users\shiham\Desktop\New\FileDetail.txt")
'MsgBox x
Dim strTemp As String
strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
FileNameNoExt = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function
Private Sub Command11_Click()
Dim F As Object
Dim xfl As String
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set F = Application.FileDialog(msoFileDialogFilePicker)
'-------------------------
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True 'Adjust the File Picker to allow multiple files to be selected
.Title = "Locate a file to attach"
.ButtonName = "Choose"
.Filters.Clear
.Filters.Add "All Files", "*.*"
.InitialFileName = "C:\"
.InitialView = msoFileDialogViewThumbnail
If .Show = 0 Then
Exit Sub
End If
'=============================
For Each varItem In F.SelectedItems
'OnlystrFile =
'------------------------
'-------------------------
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
'-------------------
'x = FileNameNoExt("C:\Users\shiham\Desktop\New\FileDetail.txt")
x = FileNameNoExt(Left(varItem, Len(varItem) - Len(strFile)) & Dir(varItem))
'MsgBox "xxx: " & x
'-----------------------
xfl = x
Next
Set F = Nothing
'=================================
Dim varFile As Variant
For Each varFile In .SelectedItems
Debug.Print varFile 'You will have to nest your code block(s) here (before NEXT) to attach each file
'-----------------------------------------------------------------------
'MsgBox "FullName: " & varFile
'MsgBox "Folder: " & strFolder
'MsgBox "file: " & strFile
'MsgBox "OnlystrFileWithoutDotExt: " & OnlystrFileWithoutDotExt
'---------------------------
Application.LoadFromText acForm, xfl, varFile
'MsgBox "file: " & strFile
'MsgBox "xfl: " & xfl
'----------------------------------------------------------------------------
Next varFile
End With
End Sub