ahtCommonFileOpenSave

  • Thread starter Thread starter RJF
  • Start date Start date
R

RJF

I have been using the code below to export a query to a .txt file, letting
the user select the path and type in the file name. It works great.

However, the users now want to still select the path, but instead of typing
in the file name, they want me to create a variable that will automatically
name the file. I created the variable YYMM_01 that contains the file name.

Can someone help me change this so that the user does not need to type in a
file name, but it automatically grabs the variable?

Thank you in advance for any help you can give me.

strfilter = ahtAddFilterItem(mystrFilter, "Text Files (*.txt)", "*.txt")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strfilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or
ahtOFN_READONLY)

DoCmd.TransferText acExportFixed, "ERSCUST_Laser_Export_Spec", "qry_Laser",
strSaveFileName
 
If this is the function you're using:

http://www.mvps.org/access/api/api0001.htm

Then the 6th argument you can pass to it is a default filename for the
filename text box. Pass your variable YYMM_01 there and see what happens.
If that's the only variable you want to pass, your code will look like this:

ahtCommonFileOpenSave( , , , , , YYMM_01)

Hope that helps...

Regards, Chris

P.S. I hope you're somehow making sure the value of YYMM_01 is different
each time it's used. Otherwise, there's a good possiblity of one user
overwriting what was saved by another user.
 
Opps! I didn't notice that you're using named variables. In that case, your
code should look like this:

strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strfilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or
ahtOFN_READONLY, _
FileName:=YYMM_01)
 
It works perfectly!

Thank you so much, Chris. I really appreciate the help and the quick
response.

-Rachel
 
Back
Top