Function ExporttoCSV()
Dim strTabletoExport As String
Dim strExportSpec As String
Dim strFilePathAndName As String
Dim blnHasHeaders As Boolean
Dim strExportFile As String
DoCmd.TransferText acExportDelim, strExportSpec, strTabletoExport, strFilePathAndName, blnHasHeaders
End Function
Private Sub ExcelOrderLineItems_Click()
On Error GoTo ExcelOrderLineItems_Click_Err
Dim strExportFile As String
ExporttoCSV = strExportFile
strExportFile = CurrentProject.Path & "\CS Order Line Items.csv"
DoCmd.TransferText acExportDelim, "Order Line Items", "CS Order line Items Qry", strExportFile, True
Private Sub ExcelOrderLineItems_Click()
On Error GoTo ExcelOrderLineItems_Click_Error
Dim strTabletoExport As String
Dim strExportSpec As String
Dim blnHasHeaders As Boolean
Dim strExportFile As String
strExportFile = CurrentProject.Path & "\CS Order Line Items.csv"
strExportSpec = "Order Line Items"
strTabletoExport = "CS Order line Items Qry"
blnHasHeaders = True
DoCmd.TransferText acExportDelim, strExportSpec, strTabletoExport, strExportFile, blnHasHeaders
MsgBox "File exported", vbInformation, "Export Complete"
On Error GoTo 0
Exit Sub
ExcelOrderLineItems_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExcelOrderLineItems_Click, line " & Erl & "."
End Sub
This is what I got out of the post to create the export specI thought we had already established you do not have a export spec?
You just appear to be cobbling words together with no idea as to what any mean?
That is just a recipe for disaster, and intellisense is meant to prevent that, but does not appear to work for you.?
Or have you just copied and pasted that from another post?
LOOK at the link I posted for the command, and read what each parameter is meant to represent, so you can understand what goes where.
I do not know the keyword version and I always use positional paremeters, but I still have to look up what goes where.![]()
'Function ExporttoCSV()
'Dim strTabletoExport As String
'Dim strExportSpec As String
'Dim strFilePathAndName As String
'Dim blnHasHeaders As Boolean
'Dim strExportFile As String
'DoCmd.TransferText acExportDelim, strExportSpec, strTabletoExport, strFilePathAndName, blnHasHeaders
'End Function
The code above still requires the folder to be created first.None of that makes any sense.
Your function is simply declareing a load of variables, not actually setting them to anything and therefore when you are running it, it comes as no surprise that access complains there is no Table name provided.
Unless you are going to reuse the export form different places there is no benefit to chucking it in a function.
If you want to structure it better try this;
SQL:Private Sub ExcelOrderLineItems_Click() On Error GoTo ExcelOrderLineItems_Click_Error Dim strTabletoExport As String Dim strExportSpec As String Dim blnHasHeaders As Boolean Dim strExportFile As String strExportFile = CurrentProject.Path & "\CS Order Line Items.csv" strExportSpec = "Order Line Items" strTabletoExport = "CS Order line Items Qry" blnHasHeaders = True DoCmd.TransferText acExportDelim, strExportSpec, strTabletoExport, strExportFile, blnHasHeaders MsgBox "File exported", vbInformation, "Export Complete" On Error GoTo 0 Exit Sub ExcelOrderLineItems_Click_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExcelOrderLineItems_Click, line " & Erl & "." End Sub
I thought we had already established you do not have a export spec?
You just appear to be cobbling words together with no idea as to what any mean?
That is just a recipe for disaster, and intellisense is meant to prevent that, but does not appear to work for you.?
Or have you just copied and pasted that from another post?
LOOK at the link I posted for the command, and read what each parameter is meant to represent, so you can understand what goes where.
Yes you are correct, I am have massive issue with coding, somehow I just can not get the intellisence as you call it in my head but when I look at a code when supplied by you guys i say Oh, yes, now I seeI do not know the keyword version and I always use positional paremeters, but I still have to look up what goes where.
![]()
I hear what you are saying, I did do the export specification as per the link, not so?I'll be blunt here, I think you need to read what people are telling you a little more carefully.
That error is about the export specification missing, not the folder for the export.
You need to create the export specification once, manually, and make sure you save it as "Order Line Items".
That's what that link is telling you to do.
You then refer to that in your export code.
@Gismo,Yes you are correct, I am have massive issue with coding, somehow I just can not get the intellisence as you call it in my head but when I look at a code when supplied by you guys i say Oh, yes, now I see
The code supplied now make so much more sense, It read easily, but still...
Oh, ok, thank you, that makes a hole lot of senseThe export spec is stored in the Database so once created will be distributed with the front end.
It only needs the export spec because you are using a comma-delimited export and need to tell it what delimiter to use.
If you were to simply export to Excel you wouldn't need it.
If you have multiple different files then you will need an export spec for each different export, if the columns change.
As I said it only needs creating once, per export definition.
When Dave says leave blank, he means omit the parameter altogether, by just putting another comma.just leave the export spec blank, and see if you like the ouptut. You don't always need an export spec.
As you indicated, it is exactly the same as what I have, infarct, it is defaultThat appears to me to say you are using the same character for separating the fields as is used for either the decimal point or the text delimiter.?
If so how is Access meant to know which is which?
You need different characters for each.
For instance, I would use
" for text delimiters
. for decimal point
, for field separator.
Yes, I actually tried thatWhen Dave says leave blank, he means omit the parameter altogether, by just putting another comma.
DO NOT put "" or " " for the spec.
Private Sub ExcelOrderLineItems_Click()
On Error GoTo ExcelOrderLineItems_Click_Error
Dim strTabletoExport As String
Dim strExportSpec As String
Dim blnHasHeaders As Boolean
Dim strExportFile As String
strExportFile = CurrentProject.Path & "\CS Order Line Items Qry.csv"
'strExportSpec = "CS Order line Items Export Specification"
strTabletoExport = "CS Order line Items Qry"
blnHasHeaders = True