Export Formatting to CSV

jarett

Board Regular
Joined
Apr 12, 2021
Messages
179
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am fumbling through some steps to automate an export from access to a csv file. I have created a macro to run a query when access opens;
VBA Code:
[CODE=vba][CODE=vba]'------------------------------------------------------------
' AutoExec
'
'------------------------------------------------------------
Function AutoExec()
On Error GoTo AutoExec_Err

    DoCmd.OutputTo acOutputQuery, "po_detail3", "MS-DOSText(*.txt)", "P:\Jarett\smtest1.csv", True, "", 1, acExportQualityPrint


AutoExec_Exit:
    Exit Function

AutoExec_Err:
    MsgBox Error$
    Resume AutoExec_Exit

End Function
[/CODE][/CODE]

All is good but the csv file that is produce has some weird formatting with all values in the first column. Also couldnt get the XL2BB add in on my excel.

My end goal is to automate this export the easiest way maybe through a task scheduler, only other issue is deleting the existing file before the new file is saved. (might be a new thread)
 

Attachments

  • Untitled.png
    Untitled.png
    25.2 KB · Views: 65
After a lot of clicking buttons on the task scheduler and playing with the macro got it to work.
VBA Code:
Function AutoExec()
On Error GoTo AutoExec_Err

    DoCmd.TransferText acExportDelim, "Smtest123 Export Specification", "po_detail3", "P:\Jarett\123.csv", True, ""
    DoCmd.Quit acSave


AutoExec_Exit:
    Exit Function

AutoExec_Err:
    MsgBox Error$
    Resume AutoExec_Exit

End Function
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I need access to close after the autoexec runs so I added a "QuitAccess" to the end of the AutoExec macro. Figured I wanted it to save anything if something changed, which nothing should change once I get it going.
 
Upvote 0
Well should of know it wouldn't be that easy, now I am getting this error when the macro tries to close access
1618525456801.png
 
Upvote 0
ditch the save and see what happens. Like I said, there's nothing to save and AFAIK it's the wrong option. Did you review the link?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top