06-09-09, 16:19 #1Registered User
- Join Date
- Jun 2009
Unanswered: Export Problem using Visual Basic
I am coding in Access and trying to export a query to a text file. This is the code I am using:
Private Sub FindAndReplaceTest_Click()
On Error GoTo Err_FindAndReplaceTest_Click
Dim oApp As Object
Dim SubsQuery As String
SubsQuery = "Retcovg apc and waiver truncated_Crosstab"
DoCmd.TransferText acExportFixed, "Default", "Part 3 final report", "C:/Documents and Settings\kpoulsen\My Documents\subsidy text.txt"
When I run this code Access somehow manages to delete the destination file before it writes anything to it, and then gives me an error saying it could not locate the file. Does anyone know what might cause this? Thanks.
06-09-09, 19:31 #2Registered User
- Join Date
- Sep 2002
- South Wales
Hi Tater and welcome to dbForums;
What are you trying to achieve here ultimately?
1 oApp is completely irrelevant (as is nearly all the code)
2 SubsQuery is just a string which says 'Retcovg aoc and waiver truncated_crosstab' - nothing to do with anything in your database at all
3 If 'Retcovg aoc and waiver truncated_crosstab' is the NAME of a query in your database, DON'T use spaces in your object names - bad chimp!
4 If you are trying to export the SQL of this query as a text field the big question is WHY on earth would you want to do that?
5 Or are you trying to export the RESULTS of a query (rather than the query itself) to a text file?
Please try and be clear about what your objectives are and im sure someone will be able to assist...Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull