?
Solved

Multiple file types filtered with OPENFILENAME

Posted on 2011-09-27
4
Medium Priority
?
475 Views
Last Modified: 2012-05-12
Hello,

I'm using the code below to call the OPENFILENAME dialog.  I need to filter xls and xlsx files, but it can only do one at a time.  When I put both extentions in as below nothing comes up.

Any ideas?  I'm working in Access 2010.

 sFilter = "All Excel Files" & Chr(0) & "*.xls, *.XLSX" & Chr(0)

    Dim OpenFile As OPENFILENAME
      Dim lReturn As Long
      Dim sFilter As String
      OpenFile.lStructSize = Len(OpenFile)
      OpenFile.hwndOwner = Me.Hwnd
      'OpenFile.hInstance = App.hInstance

        sFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls, *.XLSX" & Chr(0)
      OpenFile.lpstrFilter = sFilter
      OpenFile.nFilterIndex = 1
      OpenFile.lpstrFile = String(257, 0)
      OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
      OpenFile.lpstrFileTitle = OpenFile.lpstrFile
      OpenFile.nMaxFileTitle = OpenFile.nMaxFile
     ' OpenFile.lpstrInitialDir = "S:\clients\SENIOR LIVING\Minnesota\MN 2010\Census\Family Lists"
      'OpenFile.lpstrInitialDir = "S:\VR\1VR\VR - Ron\Development\MN_F_04122\Family_List_Test_Files"
      OpenFile.lpstrInitialDir = ""
      OpenFile.lpstrTitle = "Select the import file..."
      OpenFile.flags = 0
      lReturn = GetOpenFileName(OpenFile)
      If lReturn = 0 Then
         'MsgBox "The User pressed the Cancel Button"
      Else
         'MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
         subGetFile = RTrim(OpenFile.lpstrFile)
      End If

Open in new window

0
Comment
Question by:eshurak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 36714106
Does this work?

sFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls*" & Chr(0)
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 1000 total points
ID: 36714659
Try it like this perhaps:

    sFilter = "All Excel Files (*.xls, *.xlsx)" & Chr(0) & "*.xls; *.xlsx" & Chr(0)

The first segment is what will displayed on the "One Line"
    "All Excel Files (*.xls, *.xlsx)"

The second segment is the actual filter(s) (separated by semicolons...
    "*.xls; *.xlsx"

Chr(0) is just a Null (I think...)


JeffCoachman
0
 
LVL 3

Author Comment

by:eshurak
ID: 36718618
Thanks guys.  Both solutions work.  

chr(0) is null.  It's used as the delimiter in case you want the user to be able to choose from several filters.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36772111
great
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question