Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileDialog (2003)

    I am trying to get a button to open the File Open dialog box.
    I am using the following code, copied from the Access Help file:

    Dim dlgOpen As FileDialog

    Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDial ogOpen)

    With dlgOpen
    .AllowMultiSelect = True
    .Show
    End With

    However when I run the code my application highlights "FileDialogType:=" with the error message "Compile error named object not found"

    How can I correct this error so that my button opens the file open dialog?

    One last thing - When I select a file, I want the pathname and the filename of the file selected to be copied to a field on my database called "Picref". How can i do that?

    Thanks in advance!

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: FileDialog (2003)

    Try changing this line

    Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDial ogOpen)

    to
    Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

    (My book about Access XP uses your syntax, but my copy of Access 2003 wants the latter syntax)

    dlgOpen.SelectedItems(1) will contain a string with the file and path. so if your form is bound to the table containing "Picref" you could just say:

    me.Picref = Application.FileDialog(msoFileDialogOpen)

    Presumably in this case you don't want multiple files selected, so you should leave out the AllowMultiselect = true line.
    Regards
    John



  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileDialog (2003)

    Hi John,
    Thanks for your input.
    I tried your code - Access now highlights the term "msoFileDialogOpen" with the error message "Compile error: Variable not defined"

    I'm wondering if my 'references' are correct, or is there another reason for this?

    Thanks again.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileDialog (2003)

    You must have a reference to the Microsoft Office 11.0 Object Library for msoFileDialogOpen to be recognized. As the prefix mso indicates, msoFileDialogOpen is a constant in the microsoft office library, not in the Access (acSomething) or VBA (vbSomething) library.

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileDialog (2003)

    Thanks Hans,
    I do have a reference to the Microsoft Office 11.0 Object Library, just checked.

    My mistake - I had not included the dim statement in my updated code - but now I have a new problem:

    With the following code:

    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

    Access highlights 'dlgOpen As FileDialog' just after the 'dim' and displays the error message "Compile error: User defined type not defined"

    What could cause this?

    Thanks again

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileDialog (2003)

    According to MSKB article How to Display and to Use the File Dialog Box in Microsoft Access, the reference to Microsoft Office 11.0 Object Library should work, and I can't find any mention of problems with this in the MS newsgroups. I don't have Access 2003, so I can't test it myself. Sorry.

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: FileDialog (2003)

    I have just been testing this again, and found the following code in the Help system.

    Dim fd As FileDialog
    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd
    'Use the Show method to display the File Picker dialog box and return the user's action.
    'The user pressed the action button.
    If .Show = -1 Then
    For Each vrtSelectedItem In .SelectedItems
    MsgBox "The path is: " & vrtSelectedItem

    Next vrtSelectedItem
    'The user pressed Cancel.
    Else
    End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing



    This works for me, but I get exactly the error you describe if I remove the reference to Office 11 Object library.
    Regards
    John



  8. #8
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileDialog (2003)

    Thanks John, I'll try this and get back to you.

    A hint - perhaps - the database was originally in 2000 format, but when I upgraded it to 2003 format, the message still displayed, even though the reference still exists. Could there be an issue here? (Actually I originally created it in Access 97 and have been upgrading through several versions).

    Thanks again for all your help.

  9. #9
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileDialog (2003)

    John, thanks, that worked fine.

    Thanks again everyone for all your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •