FileDialog(msoFileDialogFilePicker)

meanster99

Meum cerebrum nocet!
Local time
Today, 05:51
Joined
May 2, 2006
Messages
62
I copied and pasted all of the code from the Northwind sample database that allows you to add/change an employee's photo.

I checked I have all the same references and have declared all variables but I still get the error "Compile Error: Variable not defined" at :

FileDialog(msoFileDialogFilePicker)

I tried to declare a variable as a FileDialog but it wasnt recognised as a variable type! (i.e Dim fd As FileDialog - but the FileDialog stayed in black text not blue!)

Does anyone know why this is happening?

Code:
Sub getFileName()
    ' Displays the Office File Open dialog to choose a file name
    ' for the current employee record.  If the user selects a file
    ' display it in the image control.
    Dim fileName As String
    Dim result As Integer
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select Employee Picture"
        .Filters.Add "All Files", "*.*"
        .Filters.Add "JPEGs", "*.jpg"
        .Filters.Add "Bitmaps", "*.bmp"
        .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
 
Its OK - I have found the problem.

I needed to reference the Microsoft Office 11.0 Object Library - I don't know how I missed it - I checked the references three times!! (as it is nearly always the problem with this type of error)
 
Using ActiveX components will give you reference headaches if you are distributing your database to other users. Use an API method to allow the users to browse for directories or files.

Browse [Find a directory or file]

HTH
 

Users who are viewing this thread

Back
Top Bottom