Hello - I have some test code that allows me to add a file path to a table - this works ok (i'm sure it could be improved - suggestions welcome!).
What I really want to do is to choose multiple files and add them to the table. I want each file path to appear in a new record in the table. I guess I need some kind of looped code. Please could someone modify my code so that multiple selected files are added to the table.
Many thanks Mark
Current code:
What I really want to do is to choose multiple files and add them to the table. I want each file path to appear in a new record in the table. I guess I need some kind of looped code. Please could someone modify my code so that multiple selected files are added to the table.
Many thanks Mark
Current code:
Code:
Private Sub btn_Add_File_DblClick(Cancel As Integer)
'Open the File Dialog so a file can be selected
Dim objDialog As FileDialog
Dim strPickedFile As String
'Open the file picker
Set objDialog = Application.FileDialog(msoFileDialogOpen)
With objDialog
.InitialFileName = "c:\temp" 'Sets default opening location
.AllowMultiSelect = True 'Sets whether multiple files can be selected
.Title = "Select File" 'Picker title
.Filters.Clear 'Clears filters
.Filters.Add "All Files", "*.*" 'Sets all files filter option
.Filters.Add "Picture Files", "*.Jpg" 'Sets JPEG files filter option
.Filters.Add "PDF Files", "*.pdf" 'Sets PDF files filter option
'open dialog and result comes back from .show as true or false
If .Show = True Then
strPickedFile = .SelectedItems.Item(1)
Else
strPickedFile = ""
End If
End With
'Check to see if a file has been selected else Exit sub
If strPickedFile = "" Then
MsgBox "No FILE was selected - Please try again", vbExclamation + vbOKOnly, "NO FILE-(msg)"
Exit Sub
End If
'Add selected File to Table tbl_File
Dim objRS As DAO.Recordset
Set objRS = CurrentDb.OpenRecordset("tbl_File", dbOpenDynaset)
With objRS
.AddNew
.Fields("FilePath") = strPickedFile
.Update
End With
objRS.Close
Set objRS = Nothing
'Sets txt_File_Selected to null
strPickedFile = ""
End Sub