Online Book Reader

Home Category

Access Cookbook - Ken Getz [102]

By Root 1959 0
that tells Windows to hide the Read Only checkbox and the Network button, and that the output path must already exist:

lngFlags = acbOFN_HIDEREADONLY Or acbOFN_NONETWORKBUTTON Or _

acbOFN_PATHMUSTEXIST

Discussion


When you call acbCommonFileOpenSave, you're actually calling the GetOpenFileName or GetSaveFileName Windows API functions. The acbCommonFileOpenSave function takes only the parameters you send it, replacing missing ones with the default values shown in Table 4-2, and fills in a user-defined data structure that both API functions expect to receive. The API functions actually do the work, and acbCommonFileOpenSave returns to you the chosen filename. Although you may find it interesting to dig into the details of calling the API functions directly, that's beyond the scope of this solution. The wrapper function, acbCommonFileOpenSave, handles a large majority of the cases in which you'll need to use common File Open/Save dialogs.

Table 4-3 lists all the values you can use in the Flags parameter of the call to acbCommonFileOpenSave. You can skip the parameter altogether, or you can use one or more of these values, combined with the OR operator. For example, to hide the Read Only checkbox and allow multiple files to be selected, use this code:

lngFlags = acbOFN_HIDEREADONLY Or acbOFN_ALLOWMULTISELECT

Table 4-3. Values to be combined in acbCommonFileOpenSave's Flags parameter

Constant name

On input

On output

acbOFN_ALLOWMULTISELECT

Allows you to select more than one filename (File Open only). Unless you also select the acbOFN_EXPLORER flag, you'll get an old-style dialog box.

The strFile member will contain the chosen path, followed by all the files within that path that were chosen, separated with spaces, as in C:\ResultFolder File1.TXT File2.TXT.

acbOFN_CREATEPROMPT

Prompts you if the selected file doesn't exist, allowing you to go on or make a different choice.

acbOFN_EXPLORER

Creates an Open or Save As dialog that uses user-interface features similar to the Windows Explorer. If you've specified the acbOFN_ALLOWMULTISELECT flag, you'll generally also want to include this flag.

acbOFN_EXTENSIONDIFFERENT

Set if the chosen filename has a different extension than that supplied in the DefaultExt parameter.

acbOFN_FILEMUSTEXIST

Forces you to supply only existing filenames.

acbOFN_HIDEREADONLY

Hides the Read Only checkbox.

acbOFN_LONGNAMES

Causes the Open or Save As dialog to display long filenames. If this flag is not specified, the dialog displays filenames in 8.3 format. This value is ignored if acbOFN_EXPLORER is set.

acbOFN_NOCHANGEDIR

Restores the current directory to its original value if the user changed the directory while searching for files.

acbOFN_NODEREFERENCELINKS

Returns the path and filename of the selected shortcut ( .LNK) file. If you don't use this flag, the dialog returns the path and filename of the file referenced by the shortcut.

acbOFN_NOLONGNAMES

Specifies that long filenames are not displayed in the File Name list box. This value is ignored if acbOFN_EXPLORER is set.

acbOFN_NONETWORKBUTTON

Hides the Network button.

acbOFN_NOREADONLYRETURN

Specifies that the returned file does not have the Read Only checkbox checked and is not in a write-protected directory.

acbOFN_NOTESTFILECREATE

Normally, COMMDLG.DLL tests to make sure that you'll be able to create the file when you choose a filename for saving. If set, it doesn't test, providing no protection against common disk errors.

acbOFN_NOVALIDATE

Disables filename validation. Normally, Windows checks the chosen filename to make sure it's a valid name.

acbOFN_OVERWRITEPROMPT

Issues a warning if you select an existing file for a File Save As operation.

acbOFN_PATHMUSTEXIST

Forces you to supply only valid pathnames.

acbOFN_READONLY

Forces the Read Only checkbox to be checked.

Set if the user checked the Read Only checkbox.

acbOFN_SHAREAWARE

Ignores sharing violations. Because Access code cannot handle the errors that occur when sharing violations occur in this code,

Return Main Page Previous Page Next Page

®Online Book Reader