GB_Joe,
I have written code to convert a qry to table and then export it to csv. I had to do two formatting - 1. For month and Year needed YMD and the second one for numbers with 4 decimal points. Everything worked great accept for the decimal points. I was going crazy until I saw this post - THANK YOU! everything is working perfect now.
Here is my code:
Private Sub cmdPrintSlit_Click()
On Error GoTo Err_cmdPrintSlit_Click
'Create an exported Slit text file (csv) and reformat it
Dim FilePath As String
Dim Ext As Variant
Dim DLString As String
Dim RsPath As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
DoCmd.SetWarnings False
db.Execute ("DELETE * FROM tblSlitReportFromQry;") 'Delete the data so I can append the data with right formatting
DoCmd.OpenQuery "qrySlitReport", acViewNormal, acEdit 'Run the query that creates the Slit Report. The query will fill the Slit status based on the order. query creates the tblSlitReportFromQry Take this out to run the qry directly to excel
DoCmd.SetWarnings True
'Get the file path from the default table
Set RsPath = db.OpenRecordset("SELECT * FROM tblTPGTEXDefaults WHERE ProgramVariable ='Slit_Confirmation'")
FilePath = RsPath!Path
DLString = "Slit_"
'Export the new table as a csv file
DoCmd.TransferText acExportDelim, "SpecTblSlitReportFromQry", "tblSlitReportFromQry", FilePath & "\" & DLString & Format(Date, "YYYYMMDD_") & Me.cmbWorkOrderId & ".csv", -1
'Eliminate the time stamp in date format
Dim lOpenFile As Long
Dim sFileText As String
Dim sFileName As String
sFileName = FilePath & "\" & DLString & Format(Date, "YYYYMMDD_") & Me.cmbWorkOrderId & ".csv"
'open the file and read it into a variable
lOpenFile = FreeFile
Open sFileName For Input As lOpenFile
sFileText = Input(LOF(lOpenFile), lOpenFile)
Close lOpenFile
'Replace Time stamp with nothing
sFileText = Replace(sFileText, " 00000", "")
'write it back to the file
lOpenFile = FreeFile
Open sFileName For Output As lOpenFile
Print #lOpenFile, sFileText
Close lOpenFile
MsgBox "The report *** " & sFileName & " *** was saved." & vbOKOnly
Exit_cmdPrintSlit_Click:
Exit Sub
Err_cmdPrintSlit_Click:
MsgBox err.Description
Resume Exit_cmdPrintSlit_Click
End Sub