Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple file types filtered with OPENFILENAME

Posted on 2011-09-27
4
Medium Priority
?
478 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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