Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User specified output txt file in Access 2007 VBA

Status
Not open for further replies.

phudgens

Technical User
Jul 8, 2004
117
US
Access 2007 VBA does not recognize the GetSaveAsFileName method that Excel VBA does. Nor am I able to find a way that Access VBA allows a user to browse for and select an existing file, or specifiy an entirely new file, to be used for outputting text data. As far as I can tell, the FilePicker method can be used if the output file already exists (and you want to overwrite it), but not if you want to create a brand new file. Can anyone tell me how to get around this?

THanks,
Paul Hudgens
Denver
 

If you want to create a new (text) file, you may just do:
Code:
Open "C:\MyTextFile.txt" For Output As #1
Print #1, "This is a text in My Text File"
Close #1

Have fun.

---- Andy
 
I'm hoping to find code that opens a dialog box that allows the user to browse for an existing file to overwrite, or to create a brand new file in a folder to which the user has navigated. Is there no such code for Access VBA?
 

If you have a UserForm, you can place a CommonDialog on it and do something like:
Code:
Private Sub CommandButton1_Click()

CommonDialog1.ShowOpen
Me.Caption = CommonDialog1.Filename

End Sub
Would that work for you?

Have fun.

---- Andy
 
Sorry for being so dense - I don't find a CommonDialog in either Access help or in the User Form toolbox.
 
Your link refers to FilePicker which assumes that the file the user wants to write to already exists. I wanted a dialog box that allows the user to specify an existing file for output, OR a brand new file in a user specified location. I finally found the CommonDialogAPI class module at an AccessForums site. This worked for what I've been trying to do. I can post that link if you like, or I can just post all the code. Thanks for the input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top