You can call it from the Click event of a command button. Much of the code I
posted is specific to what I need in my application. For example, setting up
the default directory, file type selection, default file name, etc. Here Is
the generic part with some explanation:
The only part that is required to generate the dialog and get a value
returned is:
varGetFileName = ahtCommonFileOpenSave
The above line will return the path and file chosen by the user.
It will show whatever directory is your current directory. It will have no
file types specified. The title will always be Open and the command buttons
will be Open and Cancel.
If we want to present the user with a Save dialog, we add the OpenFile
argument:
varGetFileName = ahtCommonFileOpenSave(OpenFile := False)
This does nothing more than change the title to Save As and the first
command button to Save.
It is important to note that this or any other parameters passed has any
effect on the return value of the function. All it does it return a path and
file. What you do with it is up to you.
You can also change what is in the title with this argument.
varGetFileName = ahtCommonFileOpenSave(DialogTitle:="Save Report")
Now the command button will say Open, but the title will be Save Report.
The following version will make the title Save Report and the command button
say Save
varGetFileName = ahtCommonFileOpenSave(OpenFile := False,
DialogTitle:="Save Report")
Anyway, I think you get the drift. Also, be sure to check for a zero length
string being returned. That means the user clicked Cancel or closed the
Dialog.
Good Luck.
Note I am using a variant. It could be a string variable, but the old
ActiveX control required a variant and I did not change the data types when I
adapted my code to use the API.