Access Cookbook - Ken Getz [103]
acbOFN_SHOWHELP
Shows a Help button on the dialog. Though this option works, the button will not, so its use in Access is limited.
Not all of the flags make sense for both File Open and File Save operations, of course. Your best bet is to experiment with the flags, either in your own code or using the sample form frmTestOpenSave from 04-08.MDB.
Some of the flags are useful only on return from the function call. For example, if you select the Read Only checkbox on the common dialog, Windows passes that fact back to you in the Flags parameter. To retrieve that information from your call to acbCommonFileOpenSave, pass the Flags argument in a variable, not directly as a literal value. Because acbCommonFileOpenSave accepts the Flags argument by reference, it can return the value to your calling procedure after you've selected a filename. To check if a particular flag value was set during the call to acbCommonFileOpenSave, use the AND operator with the return value, as in this example fragment (see the Solution in Recipe 11.1 for more information on using the AND and OR operators):
Dim lngFlags As Long
Dim varFileName As Variant
lngFlags = 0
varFileName = antCommonFileOpenSave(Flags:=lngFlags)
If lngFlags AND acbOFN_READONLY <> 0 Then
' The user checked the Read Only checkbox.
End if
If you pass a variable to acbCommonFileOpenSave containing the Flags information (rather than not sending the parameter, or sending a literal value), the function will return to the caller information about what happened while the dialog was in use. Several of the flags listed in Table 4-3 provide information on output. That is, you can check the state of the Flags variable, and if it contains the flags from Table 4-3, you know that the tested condition was true. For example, to open a file and then check to see if the selected file is to be opened read-only, you could use code like this:
Dim lngFlags As Long
Dim varRetval As Variant
varRetval = acbCommonFileOpenSave(Flags:=lngFlags)
If Not IsNull(varRetval) Then
If lngFlags AND acbOFN_READONLY Then
MsgBox "You opened the file read-only!"
End If
End If
As you can see in this example, you can use the AND operator to see if Flags contains the specific flag in which you're interested.
The file filter (the Filter parameter to acbCommonFileOpenSave) has a unique format: it consists of pairs of strings. Each item is terminated with vbNullChar (Chr$(0)). The first item in the pair supplies the text portion, which appears in the combo box in the lower-left corner of the dialog. The second item supplies the file specifications that Windows uses to filter the list of files. Though it doesn't matter what you use in the first item, by convention, most applications use something like this:
Oogly Files (*.oog)
listing the file description. The conventional file specification looks something like this:
*.oog
To simplify building these filter strings, use the acbAddFilter function from basCommonFile. See Step 3 for an example.
If you select the acbOFN_AllowMultiSelect flag, the result value may contain a null-delimited list of files, starting with the folder containing the files. For example, if you navigated to C:\AccessCookbook, and selected 04-04.mdb and 04-06.mdb, the return value from acbCommonFileOpenSave would contain the following text (we've used the vertical pipe symbol here to represent Chr(0) within the text):
C:\AccessCookbook|04-04.mdb|04-06.mdb
The sample form replaces the Chr(0) with a space character for you:
Private Sub cmdFileOpen_Click( )
Dim varResult As Variant
varResult = FileOpenSave(True)
Me.txtFileOpen = Replace(varResult, vbNullChar, " ")
End Sub
If you allow multiple file selection, it's up to you to parse the various the file path and names yourself.
Take the time to study all the parameters in Table 4-2 and all the options in Table 4-3. There's not room here to go into detail for each one, so your best bet is to try out all of them. You can play with frmTestOpenSave to test the effects of some of