Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CommonDialog API (XP)

    Hi,
    i am using the CommonDialog API to let a user select a file via the open dialog. how do i construct the filter type filter?

    i am lost for the seperator character

    Excel Files (*.xls)|*.xls| All files (*.*)| *.* filters excel files and then all files

    how do i costruct a filter for Excel and Word files and then All Files?

    Word and Excel Files (*.xls and *.doc)|*.xls ; *.doc| All files (*.*)| *.* doesnt work (thats a semi colon)
    TIA

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

    Re: CommonDialog API (XP)

    Try omitting the spaces before and after the semicolon.

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

    Re: CommonDialog API (XP)

    BTW, Access (and Office) 2002 has a new FileDialog object, its easier to program than the CommonDialog.

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CommonDialog API (XP)

    Two examples

    <pre>strFileFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls" & Chr(0) & _
    "Word Files (*.doc)" & Chr(0) & "*.doc" & Chr(0) & _
    "Picture Files (*.gif, *.jpg, *.bmp)" & Chr(0) & _
    "*.gif; *.jpg; *.bmp" & Chr(0) & _
    "PDF Files (*.pdf)" & Chr(0) & "*.pdf" & Chr(0) & _
    "Text Files (*.csv, *.txt)" & Chr(0) & "*.csv; *.txt" & Chr(0)


    strFileFilter = "Files (*.xls, *.doc, *.mdb, *.mde, *.pdf, *.csv, *.txt)" & _
    Chr(0) & "*.xls; *.doc; *.mdb; *.mde; *.pdf; *.csv; *.txt" & Chr(0)
    </pre>


  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CommonDialog API (XP)

    Hans, how would i reference the FileDialog object? Currently i am using the method described here 473377

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

    Re: CommonDialog API (XP)

    Here is a simple example:

    Sub GetFilename()
    Dim strFilename As String
    With Application.FileDialog(msoFileDialogOpen)
    .Filters.Clear
    .Filters.Add "Word and Excel files", "*.doc;*.xls"
    .Filters.Add "All files", "*.*"
    If .Show = True Then
    strFilename = .SelectedItems(1)
    MsgBox "You selected " & strFilename
    End If
    End With
    End Sub

    Click in any of the keywords and press F1 for online help.

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CommonDialog API (XP)

    hmmm, tried something like that before i posted; getting this error

    Method 'FileDialog' of object '_Application' failed

    do i need to add a new reference?

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

    Re: CommonDialog API (XP)

    You need a reference to the Microsoft Office 10.0 Object Library if you're using Office XP (the FileDialog was not available in Access 2000 and before)

  9. #9
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CommonDialog API (XP)

    by jingo, it works!


    many thanks Hans

Posting Permissions

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