Export Formatting to CSV

jarett

Board Regular
Joined
Apr 12, 2021
Messages
87
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: 11

jarett

Board Regular
Joined
Apr 12, 2021
Messages
87
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

jarett

Board Regular
Joined
Apr 12, 2021
Messages
87
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

jarett

Board Regular
Joined
Apr 12, 2021
Messages
87
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
2,181
Office Version
  1. 365
Platform
  1. Windows
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?
 

Forum statistics

Threads
1,136,864
Messages
5,678,214
Members
419,751
Latest member
TryingtoLearnVBA

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
Top