The following lines of code should export data from a query to a *.txt file, but results in an error.
strPath = "N:\apprais\targetDirectory\"
DoCmd.TransferText acExportDelim, "spcDataFile", "qryExportAppraisal", strPath & "DATAFILE.TXT"
Based on this https://msdn.microsoft.com/en-us/library/office/ff835958.aspx, I don't think it should be necessary to have a Schema.ini file (unless it's a fixed-width file). Also when I executed the command in an older version of the application, I was able to export the data from the query to the *.txt file without the Schema.ini file.
Ultimately, I need to know if I'm correct about the Schema.ini, and if I am, is there a default location that specification files are saved to in Access 2010? I can't seem to find where it's defined. I've looked in External Data > Saved Imports/Exports, but am not able to find anything resembling spcDataFile
Related
I'm having a problem with DoCmd.TransferText acExportDelim where it will export the desired file from my query, but it will not format the outputted file name as expected and it places the file one folder up in the selected folder path.
I do the entire export operation via a form. The user selects the folder path in the form, then the query ID, and the VBA code appends them together in the "FileName" parameter of DoCmd.TransferText acExportDelim like so:
DoCmd.TransferText acExportDelim, "Export Specification", "QueryName", "Me.FileLocationTextField.Value Me.QueryIDComboBox.Value .csv", TRUE
The above code will output the file from the query, but it will have a file name like "Me#FileLocationTextField#Value Me#QueryIDComboBox#Value". The file has the correct contents, it's just that the name is not the text that is stored in the Query ID Combo Box, which is what I would prefer.
The other issue is that the File Location is always one folder up in the folder path. So if the user selects "C:\Users\User\Documents\Exported Files\CSV Files" the file will be exported to "C:\Users\User\Documents\Exported Files".
I've tried setting the confirming the value of Me.FileLocationTextField.Value with a MsgBox and it is indeed showing the correct and full path before it is sent to TransferText acExportDelim. I've also tried several combinations of escape characters and concatenations for the FileName parameter but none have worked to get the file name or the folder path to work correctly.
I have a .csv file on my Desktop. The file name is very long and includes special characters such as brackets, e.g.:
[ABCD 012015] ACCT 1117 - Section A10 Grades-20150316_1937-comma_separated.csv
where the first 36 characters of the filename are a constant. The remainder of the file name changes upon each instance of a download.
I have tried VBA to import the file into an Access with a DoCmd.TransferText and I get errors. I have discovered that there is a limit to the length of a filename that the DoCmd.TransfertText can handle.
So, I need to first rename the file manually, then I can use VBA. Renaming a file is relatively easy with VBA, but I would like to use the info provided in the original filename such as Section A10 (which would make it unique, since there are other Sections labelled A01, A02, etc.) and rename the .csv file as A10.csv, so this means searching for a string AND replacing it. Since the Section can be different, how do I write the code and rename the file then import it with VBA?
So, far I have bits and pieces, but cannot put them together:
Name OldPathName As NewPathName
DoCmd.TransferText acImport, "AME_Grades", strTable, strPathFile, blnHasFieldNames
I am using an import specification AME_Grades to make it cleaner in the Access table.
Any suggestions? TIA
I'd suggest to use FileCopy function before you start importing data from csv file into MS Access.
Dim OldPathName As String, NewPathName As String
OldPathName = "FullPathToVeryVeryLonLongLongFileName.csv"
NewPathName = "FullPathToShortFileName.csv"
FileCopy OldPathName, NewPathName
DoCmd.TransferText acImport, "AME_Grades", strTable, NewPathName, blnHasFieldName
I currently have a 'Save Export' task that is saving a table (+1 million records) to an .xlsx file on a SharePoint folder via mapped network drive. I want to add the date to the file Excel file name.
Currently for Export-Excel Spreadsheet:
File Name is: U:\Reporting\Extracts\Excel_filename.xlsx
File format: Excel Workbook (*.xlsx)
Under Specify export options: I don't have anything checked.
With Date:
File Name is: U:\Reporting\Extracts\Excel_filename_mm_dd_yyyy.xlsx
File format: Excel Workbook (*.xlsx)
Under Specify export options: I don't have anything checked.
I would want the final file name to be: Excel_filename_09_18_213.xlsx
I don't want to use VBA because creating the .xlsx file takes over 4 hours. Export the table directly to the SharePoint folder is faster, but I need to update the file name with the current date. Could I create a macro that adds the date to the file name before it is posted to SharePoint? Is there a 'RunCommand' or 'RunCode' command that I could run that would generate the file name with the date?
I have tried the following for the file name, and they didn't work. I get "Failed creating file." "The specification failed to execute. Try re-creating the specification.":
U:\Reporting\Extracts\Excel_filename&(Format(Date()),"yymmdd"))&.xlsx
U:\Reporting\Extracts\Excel_filename%Date:~12,2%%Date:~4,2,%%Date:7~2%.xlsx
"U:\Reporting\Extracts\Excel_filename"&(Format(Date()),"yymmdd"))&".xlsx"
U:\Reporting\Extracts\Excel_filename_(Format(Date()),"yymmdd")).xlsx
Many thanks in advance.
I'd use VBA for this task. I wouldn't save it directly from Access onto Sharepoint folder however, I'd save it to a temporary location on the local disk and then copy it over - much quicker. If you are talking about pulling the data from a local Access file - then it shouldn't be taking 4 hours.
DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel7, "myAccessTable", _
"C:\MyExcelExport_" & format(date(),"yyyy-mm-dd") & ".xls", True
on the macro line set destination
="C:\YourFolder\fileName" & Format(Date(),"ddmmyy") & ".xls"
I created a test MS Access DB to export a table to Excel and a text file.
This works for Excel:
DoCmd.OutputTo acOutputQuery, "QryExportToExcel", _
acFormatXLS, XFile, False
For the text file, I created a specification and used this code
DoCmd.TransferText acExportDelim, "Mytable Import Specification", "mytable", "D:\myfolder\test1.txt", False
In the error message, I get "test1#txt".
The Microsoft Office Access database engine could not find the object
"test1#txt". Make sure the object exists and that you spell its name
and the path name correctly.
I tried creating test1.txt in the same path. To my surprise, this deleted the file which is already present.
Software: MS ACCESS 2007
The Microsoft Office Access databasse engine could not find the object "test1#txt". Make sure the object exists and that you spell its name and path name correctly.
This is a generic (and rather useless) error message that Access outputs in case anything goes wrong. One example would be a misspelled field name in the import/export specification.
You can get the "real" error message by trying the import operation "manually" in the Access user interface (rather than through code).
The question author reported the problem was "because I was using an Import Specification for Exporting a file."
They resolved the problem by using an Export Specification.
Because you are doing DoCmd.TransferText, Access is expecting that the file Test1.txt exists in that location. Try creating the file first, and then do a transfer of the text.
You can try this code before the export to create the file:
Public Sub CreateExportFile()
Dim strFileName As String
Dim SomeStringToOutput
strFileName = "d:\myfolder\test1.txt"
Open strFileName For Output As #1
End Sub
I was having a similar situation and found that a file schema.ini was in the destination folder. This was created when an acExportMerge was performed previously and it caused this error. Make sure that file has been deleted prior to executing a new TransferText.
I inherited a huge, bulky MS Access database and am assigned to solve a problem in it. The problem is as follow...
System A exports its data to a pipeline-delimited .txt file. The files has special characters working correctly, for example the value "Müller" shows when opening this file in notepad or Excel.
Next, the Access DB imports the .txt file and stores the result in an internal employees table. The last name field is of data type "memo". The method to import data from the .txt file to MS Access is as follow:
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True)
After running this import and viewing the employees table I noticed that names with special characters are screwed up. "Müller" becomes "M├⌐ller" for example. I investigated some online help and found out that can include a "codepage" parameter in the TransferText call, so I set it to 65001 (which appearantly is the codepage for unicode):
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True, _
, _
65001)
Now that I have ran the import script again, I see no difference whatsoever, the special characters are still misformed. I'm running out of steam so I hope one of you has some advise on how to resolve this...
Both versions of your TransferText operation are using a SpecificationName named tblEmployees. What Code Page is specified in that Specification?
Try importing the text file manually. Choose "Advanced" from the Import Text Wizard. Then select Unicode in the Code Page list box. You may need to test with different Code Page selections until you find which one imports your text correctly.
Which ever Code Page selection works, save your choices as a specification and use it in your TransferText command, without supplying a separate CodePage parameter.
Using CodePage=1200 (msoEncodingUnicodeLittleEndian) solved the issue in my case.
there is an unicode list to use in VBA:
http://msdn.microsoft.com/en-us/library/office/aa432511(v=office.12).aspx