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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button Export Text File 1

Status
Not open for further replies.

ThunderGeek

Technical User
Nov 29, 2004
38
US
I have a form with command button to export a text file with this code attached to the onclick, the code blelow works well:
Code:
DoCmd.TransferText acExportDelim, "ProductsNewExportSpecification", "ProductsNew", "C:\SHOPSITE\products\New Folder\newproducts.txt", True, ""


However I would like to change the file name to a text string stored in a combobox named [SupplierBox] on a form named [Supplier].

I keep getting error code and know that I am not getting the string in properly.
Any help is appericated
Thanks Thundergeek
 
How are ya ThunderGeek . . .

In a [blue]module[/blue] in the [blue]modules[/blue] window, copy/paste the following routine:
Code:
[blue]Public Sub XferToFile([b]FileName[/b] As String)
   Dim [purple][b]FileSpec[/b][/purple] As String
   
   [purple][b]FileSpec[/b][/purple] = "C:\SHOPSITE\products\New Folder\" & [b]FileName[/b]

   DoCmd.TransferText acExportDelim, _
                      "ProductsNewExportSpecification", _
                      "ProductsNew", _
                      [purple][b]FileSpec[/b][/purple], _
                      True, _
                      ""
End Sub[/blue]
A call to the routine would look like:
Code:
[blue]   Call XferToFile("newproducts.txt")[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
I modified the code just a bit, added the FileName = line.

Code:
Public Sub XferToFile(FileName As String)
   Dim FileSpec As String
   FileName = Forms!supplier!SupplierBox & ".txt"
   FileSpec = "C:\SHOPSITE\products\New Folder\" & FileName

   DoCmd.TransferText acExportDelim, _
                      "ProductsNewExportSpecification", _
                      "ProductsNew", _
                      FileSpec, _
                      True, _
                      ""
End Sub
works great, thanks for the help.
ThunderGeek
 
ThunderGeek . . .

If you take a good look I [blue]designed the routine to be universal[/blue] (you can call it from anywhere in the DB including VBA).

To [green]maintain universal posture[/green], [purple]instead of the FileName line[/purple] your call would be:
Code:
[blue]   Call XferToFile(Forms!supplier!SupplierBox & ".txt")[/blue]

[blue]The choice is yours! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks - I totally missed that simple solution.
ThunderGeek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top