How do I limit file types in FileOpen?

Clueless Newbie

Immortal. So far.
Local time
Today, 21:44
Joined
Feb 6, 2004
Messages
48
Hi all,

sorry if this is a daft question - I come from the PERL and JavaScript corner originally and my boss has suddenly decided that I should do some Access stuff as well... :rolleyes:

In a project of mine, I'm using the following function:

Code:
Function LaunchCD(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.hwnd
    sFilter = "AdobeAcrobat (*.pdf*)" & 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 = "C:\"
    OpenFile.lpstrTitle = "Bitte wählen Sie eine Datei aus."
    OpenFile.flags = 0
    lReturn = apiGetSaveFileName(OpenFile)
        If lReturn = 0 Then
            MsgBox "Sie haben leider keine Datei ausgewählt!", vbInformation, _
              "Bitte wählen Sie eine Datei aus."
         Else
            LaunchCD = Trim(OpenFile.lpstrFile)
            Do Until Right(LaunchCD, 1) <> Chr$(0)
                Debug.Print LaunchCD
                LaunchCD = Left(LaunchCD, Len(LaunchCD) - 1)
            Loop
         End If
End Function

Once the file is selected, its name including the entire path is written into a text field and, of course, also saved to my table.

What I would also like to do is to limit the files shown for selection in the FileOpen dialog to just .pdf files. Everything else should be suppressed/made invisible.

Alternatively, I could also give out an error message whenever a non-PDF file is selected. I would, however, prefer the first solution, if at all possible.

Does anyone have a clue how I could go about this by any chance? Any help would be most appreciated. :)

Cheers & have a nice day!

Ute
 
Remove this part:

Code:
& Chr(0) & "*.*"
- it's a wildcard saying "All files"
 
I had already tried that but it doesn't make any difference whatsoever, I'm afraid. Are there any other things I could try?

Thanks & regards,

Ute
 
Bearing in mind the change above, try this also: (*.pdf*) to (*.pdf)
 
Same result as before, I'm afraid... Is this perhaps because I'm using a dialog box that comes straight from the system rather than Access itself?
 
You might want to visit a site called "The Access Web." It contains several code segments, including one that allows you to limit the file type usable in an Open.

Web reference to home page:

http://www.mvps.org/access/

Then browse through their index or table of contents. Normally i would point you to something here, but it happens I saw some code there earlier this week on exactly this subject.
 
Oh, thanks, I'll try that a.s.a.p. and let you know whether it works. :)

Have a nice weekend!

Ute
 
This example shows the use of several different dialog boxes. Included in the forms code is several examples of how to set the types of files you want.

Dave
 

Attachments

@Oldsoftboss: That one was precisely what I was looking for, thanks a bunch! :)

Ute
 

Users who are viewing this thread

Back
Top Bottom