I have an access97 database and I am trying to write some code to export to a CSV file - (I am new to VBA).
I have this working however, there is one field that I am exporting that is a currency so in it for example is £3,456.00 - when I export to the CSV I get exactly this - however I need it to just be the number i.e 3456.00.
On a similar issue - I have the date as dd/mm/yyyy and I wonder if there is a way to convert that in VBA to yyyy-mm-dd?
Please bear in mind any solutions has to be simple due to my limited knowledge!
Sorry about the delay; seemingly easy things took longer. As I assumue from your:
DoCmd.TransferText acExportDelim, "olly_csv", "olly aorder export", "\\10.0.0.38\nw_upload\aorders.csv"
that you have an export specification "olly_csv" that determines how to export the
resultset of the SELECT query "olly aorder export" to the file "aorders.csv"
in the destination folder "\10.0.0.38\nw_upload".
The easy way to export the CURRENCY field(s) as plain Double/Float/Single number
and the DATE field(s) with a format of your choice (dd/mm/yyyy) would be to
request just that in the export specification. I found no way to do that in Access
2000 (As far as I can see, there are limited ways to pick date formats, but the features of the Import Wizard to deal with the types of columns are not implemented by the
Export Wizard).
The Docs about "TransferText" (sorry, Access 2003) state:
SpecificationName Optional Variant. A string expression that's the name of
an import or export specification you've created and saved in the current
database. For a fixed-width text file, you must either specify an argument or
use a schema.ini file, which must be stored in the same folder as the
imported, linked, or exported text file. To create a schema file, you can use
the text import/export wizard to create the file. For delimited text files
and Microsoft Word mail merge data files, you can leave this argument blank
to select the default import/export specifications.
Now there are to schools of Microsoft Docs philology: The optimists will read
that as: If you don't pass an export specification and have a suitable schema.ini
file, then the export process will adhere to the specs in the file. The pessimists
will say: Microsoft never agreed to fullfill your pipe dreams - if you don't
specify an argument for a non-fixed-width file, the TransferText command will
use some obscure default export specification (please pay a consultant to
seek and change it).
Let's be optimistic!
So create a schema.ini file with a section for "aorders.csv". For my tests I
used a table
Tabelle: OlliesOrders
Name Typ Größe
OrderId Long Integer 4
Amount Währung 8
DateDue Datum/Uhrzeit 8
(sorry about the German; Amount is Currency, DateDue Date/Time). For that table
the schema.ini section looks like:
[aorders.csv]
ColNameHeader=True
CharacterSet=1252
Format=Delimited(;)
DateTimeFormat=dd/mm/yyyy
Col1=OrderId Integer
Col2=Amount Float
Col3=DateDue Date
You'll have to adapt this example to your fields. Do you want column headers? Is the
windows codepage ok? What about field separators? I had to use ; (German locale), you
may need "Format=CSVDelimited". Look here for some background. Then call
DoCmd.TransferText acExportDelim, , "olly aorder export", "\\10.0.0.38\nw_upload\aorders.csv"
and check if optimists rule.
For pessimists:
Create a new query on the table to export (from). Change the type to Ausführung/Execute (?)
and edit the SQL until it looks like:
SELECT OlliesOrders.* INTO [aorders.csv] IN 'M:\trials\23forum\SOTrials\txt' [TEXT;] FROM OlliesOrders;
resp.:
SELECT YourFieldsList INTO [aorders.csv] IN '\\10.0.0.38\nw_upload' [TEXT;] FROM YourTable;
and execute it (from the query window or a macro/module Sub). My result:
"OrderId";"Amount";"DateDue"
1;1411,09;29/04/2011
2;123,45;13/04/2011
ADDED: Evidence for my claim, that you can't specify types in the Export Wizard:
Export
Import
Related
We have a .txt file with encoding UTF-16 LE (discussed here, as well). We need to load this file into an Azure SQL database. We are first trying to convert this file to a csv format by using Text Import Wizard of Data Excel 365 wizard. But if we use the ^|^,^|^ as a custom delimiter, the first and last columns still end up with ^|^ value.
Question: What may be possible solutions/work arounds for converting this type of file to csv?
Remarks: This is a huge file (1GB) with about 150 columns. Following is just a sample for explaining the scenario in this post.
Sample of the txt file:
^|^Col0^|^,^|^Col1^|^,^|^Col2^|^,^|^Col3^|^,^|^Col4^|^,^|^Col5^|^,^|^Col6^|^,^|^Col7^|^
^|^1234^|^,^|^4600869848^|^,^|^6000.00^|^,^|^2021-12-20 10:16:19.3600000^|^,^|^False^|^,^|^^|^,^|^^|^,^|^2^|^
^|^5431^|^,^|^3425143451^|^,^|^30000.00^|^,^|^2021-12-13 10:27:44.9030000^|^,^|^False^|^,^|^^|^,^|^^|^,^|^2^|^
.....................
............................
After using the delimiter ^|^,^|^ in Excel text import wizard
Instead of mentioning the ^|^,^|^ as custom delimiter, you can mention comma as a delimiter, that will give you a result like below:
Then you can record a macro to replace the desired characters which is ^|^ after importing is done as mentioned in below link:
Create A Macro Code To Achieve Find And Replace Text In Excel
I'm trying to do an export from access into a text file via a query
select CustomerName
into [Text;FMT=TabDelimited;HDR=NO;DATABASE=C:\Temp\;].CustomerList.txt
from Customer
however, every line is getting wrapped in double quotes. Is there a way to turn off the quoting (I'm only ever setting one column), or can I use a custom quote character (e.g. set it to blank)?
Method 1
You have to add manually a schema.ini in the directory you wish to export
In your case, it should contain :
TextDelimiter="none"
Method 2
Another way to do it is to use the TransferText method, with :
SpecificationName Optional Variant. A string expression that's the
name of an import or export specification you've created and saved in
the current database. For a fixed-width text file, you must either
specify an argument or use a schema.ini file, which must be stored in
the same folder as the imported, linked, or exported text file. To
create a schema file, you can use the text import/export wizard to
create the file. For delimited text files and Microsoft Word mail
merge data files, you can leave this argument blank to select the
default import/export specifications.
for your export specification, which is a oneshot operation, you will use the wizard and there you have an "advanced" button bringing a menu where you can set the text delimiter to nothing.
Google is your friend. You've got enough clues now to sort it out.
My client has a Windows regional settings that has comma as a decimal place separator and semicolon as a list separator, which is a typical format settings for most European countries. When my code tries to run DoCmd.TransferText without export specification, it throws this error:
So my solution would be to use export specification as adviced here http://msdn.microsoft.com/en-us/library/office/ff835958%28v=office.15%29.aspx
Well, as I found (for example here: Docmd.TransferText question) the only way to create the user specification is to manually run some Export wizard. In it I can set which decimal place separator and which list separator I want to use. Looks good, but there is a problem: the export specification also contains information about the exported columns and their formats. But I am creating my export query dynamically, the columns are different for each export run. How can I use the export specification? Or is there any other solution to my problem?
Note: Of course, I cannot force my client to change his Windows regional settings. Neither can I export the CSV files just writing value by value to raw text file output in VBA because the queries are large and this would probably take hours to finish. I do not mind if the final CSV files have commas as list separators and points as decimal separators (US format) or semicolons as list separators and commas as decimal separators (local format settings) - I do not care because I can tweak the further steps in the processing of the CSVs accordingly.
You have two choices: (a) use the inline-text version of the export format specification, or (b) create an export specification using the wizard, then use normal Access database methods to modify the values in the export specification table.
I need to export varbinary data to file. But, when I do it using Column Transformations in SSIS, the exported files are corrupt. There are few junk characters at the start of the file. On removing them, the file opens fine.
A similar post for BCP, says that these characters specify the data length.
Would like to know how to address this issue in SSIS?
Thanks
Export transformation is used for converting the varbinary to files.I have tried something similar using Adventure works which has image type of var-binary data.
Following Query is used for the Source query. I have Modified the query
since it does not have the full path to write image files.
SELECT [ProductPhotoID]
,[ThumbNailPhoto]
,'D:\SSISTesting\ThumnailPhotos\'+[ThumbnailPhotoFileName]
,[LargePhoto]
,'D:\SSISTesting\LargePhotos\'+[LargePhotoFileName]
,[ModifiedDate]
FROM [Production].[ProductPhoto]
Used the Export column transformation[also available in 2005 and
2008] and configured as follows.
Mapped rest of the columns to the destination.
After running package all the image files are written into the
respective folders[D:\SSISTesting\ThumnailPhotos\ and D:\SSISTesting\LargePhotos].
Hope this helps!
I'm trying to import a text file into an access database. It's not one I've written myself but the spec for the delimited text file is set up properly and the file imports properly using the wizard. When I try to use the import functions of the app itself, the ImportError table tells "Field Truncation" for one of the fields. Any help would be appreciated.
I would suggest examining each column that you're bringing in, and then measuring that against your table column properties in table "Design" mode.
Common things I've seen throw this error are:
Imported text exceeding the 255 character limit of a field (in which case you can change the field type to memo)
Date fields being set up as short date format, and then trying to import long dates/times into the field.
Text other than "yes/no/true/false" being imported into Yes/No/True/False fields.
Double-check your columns for similar names, and then check the data being imported. Sometimes when multiple people are working on a project and appending data, columns with similar names can get confused...especially if the column is collapsed so that its name is not entirely showing.