Solved

Multiple file types filtered with OPENFILENAME

Posted on 2011-09-27
4
467 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
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 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 250 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
My experience with Windows 10 over a one year period and suggestions for smooth operation
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now