I am trying to run the following code to select a photo to display in a form. The code is called by a command button on the form.
Each time I try to run the code I the "Dim dlgOpen As FileDialog" is highlighted and I receive the message "User-Defined Type not defined". If I press F1, the File Dialog Property details open, giving me the format for the code. I have checked against this and everything seems to be in order.
Can someone please advise where I am goin wrong.
Thanks a lot
John
Code:
Sub getFileName()
' Displays the Office File Open dialog to choose a file name
' for the current trophy record. If the user selects a file
' display it in the image control.
Dim fileName As String
Dim result As Integer
Dim dlgOpen As FileDialog
Dim varFile As Variant
Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgOpen
.Title = "Select Trophy Picture"
.Filters.Add "JPEGs", "*.jpg"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![FirstName].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub
Each time I try to run the code I the "Dim dlgOpen As FileDialog" is highlighted and I receive the message "User-Defined Type not defined". If I press F1, the File Dialog Property details open, giving me the format for the code. I have checked against this and everything seems to be in order.
Can someone please advise where I am goin wrong.
Thanks a lot
John