Solved

Multiple file types filtered with OPENFILENAME

Posted on 2011-09-27
4
474 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

729 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