Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User-Defined Type Not Defined 1

Status
Not open for further replies.

rj51cxa

Technical User
Mar 16, 2006
216
GB
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.

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
 
I'm using Access 2003 and have ensured that I have Microsoft Office 11.0 Object checked in the References.
 
Hi Remou, thanks for the hint but that was the one I was trying to use. However, I think I have found an easier way to display a picture using the code

Code:
Me.ImageFrame.Picture = Me.Photo

This code is invoked after I update a combo box to select the record I require. It works fine except when the photo field in the underlying table is blank (no photo available), when I receive an error message:

"Run-time error 94 - Invalid use of Null"

Is there any way I can modify this code so that the Image Frame remains blank if there is no photo?

Thanks a lot
John


 
One difference is in:
Dim fDialog As Office.FileDialog
and yours:
Dim dlgOpen As FileDialog

Perhaps:

Code:
If IsNull(Me.Photo) Then
   Me.ImageFrame.Visible=False
Else
   Me.ImageFrame.Picture = Me.Photo
End If
 
Thanks Remou, your code worked first time in that I selected a record that had a photograph and the picture was displayed. I then selected a record for which there was no photograph. Nothing was displayed and there was no error message. Now comes the problem - I then selected a record for which there was a photograph and nothing was displayed.

I can't figure this one. My code now looks like this:

Code:
  Private Sub Select_Trophy_AfterUpdate()
  ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TrophyName] = '" & Me![Select Trophy] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
     
   If IsNull(Me.Photo) Then
   Me.ImageFrame.Visible = False
Else
   Me.ImageFrame.Picture = Me.Photo
End If
End Sub

Any further ideas would be most welcome.

Best Regards
John
 
[blush]

Code:
If IsNull(Me.Photo) Then
'Hide the control if there is NO photo
   Me.ImageFrame.Visible=False
Else
   Me.ImageFrame.Picture = Me.Photo
'Show the control is there is a photo
   Me.ImageFrame.Visible=True
End If
 
Do you have a reference to MS Office object library? It is optional in ms access.

combo
 
Thanks Remou, that solved the problem. Have a star for Christmas.

Combo, thanks for the tip, I have added that option as well.

Best wishes for Christmas to all readers
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top