Private Sub btAddPhoto_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim strPath As String
On Error GoTo errHandler
' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box (or not)
fDialog.AllowMultiSelect = False
' Set the title of the dialog box.
fDialog.Title = "Select photo"
' Clear out the current filters, and add our own.
fDialog.Filters.Clear
fDialog.Filters.Add "JPEG Pictures", "*.jpg"
fDialog.Filters.Add "BMP Pictures", "*.bmp"
fDialog.Filters.Add "PNG Pictures", "*.png"
fDialog.Filters.Add "All files", "*.*"
fDialog.ButtonName = "Select"
fDialog.InitialView = msoFileDialogViewLargeIcons
fDialog.InitialFileName = CurrentProject.Path & "\Pics" 'or select your own initial folder
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If fDialog.Show = True Then
'Loop through each file selected and add it to our list box.
strPath = Trim(fDialog.SelectedItems(1)
Pic1.Picture = strPath
'and now you need to update Photo field in your table with strPath
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
errHandler:
If (Err.Number = USER_CANC) Then ' User cancelled action.
Resume Next
Else
Exit Sub
End If
End Sub
End Sub