Code below
'open file dialog box to open a file
'Private Sub fileNamePicked_Click()
Function fileNamePicked_Click() As String
On Error GoTo subError
'Add " Microsoft office 14.0 object library " in referances and
'visual basic for app
'M/c Access 16.0 object libary
'OLE AUTO
' M/C office 16.0 database eng
'mc office 16.0 object labary
'm/c script runtime
Dim imagename As String
Dim FDialog As Office.FileDialog
Dim Varfile As Variant ' the varfile is the name fo files shown in the fdialog box
imagename = "" ' clears the date if any in the variable
txtSelectedName = "" ' clears the data if any in the variable
' set up the file Dialog
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)
With FDialog
.InitialFileName = ""
.Title = " Pick the photo file you want to import but you can only pick gif or jpg files types"
.AllowMultiSelect = False ' note for images set this to false
.InitialFileName = "C:\wamp64\www\LandMweb\images\ " 'Folder picker needs trailing slash, this will leave the file name at the bottom blank
.Filters.Clear
.Filters.Add " gif image files", "*.Gif"
.Filters.Add " Jpg image files", "*.JPG*"
'below are extra file filtters you may wish to use
'.Filters.Add " Excel files", "*.xls*"
'.Filters.Add " Excel files", "*.xlsx*"
'.Filters.Add " Excel files, macro enabled", "*.xlsm*"
If .show = True Then ' the user picked open, if is false userpick cancal
If .SelectedItems.Count = 0 Then
MsgBox "You did not pick a file", , , vbCritical + vbOKOnly, _
"an error has occrred"
GoTo SubExit
End If
'the for loop below is used only when mulit select is true
For Each Varfile In .SelectedItems
txtSelectedName = txtSelectedName & Varfile & vbCrLf '(vbcrlf is for a carrage return to start a new line)
imagename = txtSelectedName
Next
Else
'user cancelled dialog without choosing
End If
End With
fileNamePicked_Click = txtSelectedName
Me.Image77.Picture = txtSelectedName 'Me.imageADD1
Me.Refresh
SubExit:
On Error Resume Next
Set FDialog = Nothing
Exit Function
subError:
MsgBox " an Error number:" & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
"AN error occurrred, i think because i picked execl only "
GoTo SubExit
End Function