Yes, it is possible to have the user specify the filename for the export. There are two EASY ways to do it. The first is to simply place a textbox on the form where your export button is, and have the filename in that.
Let's say that you create a textbox called ExportFilename on your SecondaryMenuF form right below your button. Now, in the FILENAME parameter for the macro that performs the export, just put:
=[Forms]![SecondaryMenuF]![ExportFilename]
We learned about this technique in Access 202, lesson 2, where we shared values between two forms. You can use this same notation in macros, queries, VBA code, etc.
The other way you could do it, would be to use the InputBox command to prompt the user for the filename when the macro runs. Here's the syntax:
And that would prompt the user for the filename, giving them a default vallue of C:\ExportFile.xls. We learned about InputBox in Access 306.
There is another way you could do it... but that would involve introducing the FILE and FOLDER controls to your database. I personally don't like pulling in extra controls into my database unless absolutely necessary, but Microsoft does make nice controls that you can browse for files and folders with. I cover them in my Visual Basic 106 class, and the same controls work in Access too.
You're still going to have to refer to the filename you select in your macro though - so you'll still need the Forms!FormName!Field notation.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Microsoft Access 308.