PC Review


Reply
Thread Tools Rate Thread

changing format of fields when importing

 
 
geert.van.ransbeeck@telenet.be
Guest
Posts: n/a
 
      9th Mar 2009
Hello

The code below imports a csv-file into a table.
For the field F18 I don't get what I want.
In the csv-file 'F18' is of a 'general' format. I don'g get the data
correctly, it has been transformed into a 'time format'. Even if I add
the ALTER TABLE ALTER COLUMN statement to change the data into numbers
doesn't help. Now I have some blancs where there even shouldn't be
one.

Can somebody help?

DoCmd.DeleteObject acTable, "TBL_Import_TPXP_Radi_College_Newcsvfile"
DoCmd.TransferText acImportDelim, ,
"TBL_Import_TPXP_Radi_College_Newcsvfile", "X:\TRANSIT60\AFTP
\USPB1815\RADICOL\NEW.CSV", False, ""

DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
ALTER COLUMN [F18] number"
 
Reply With Quote
 
 
 
 
Dale Fye
Guest
Posts: n/a
 
      9th Mar 2009
Don't delete the destination table. Create it once, modify the field
datatypes as appropriate.

Then delete all the records.

Now use the GetExternalData wizard to import the CSV, but when you do this,
click on the "Advanced" button in the lower left corner of the wizard to open
the Import Specification Wizard. It will allow you to individually identify
the datatype for each field in your csv file, as well as indicating which
fields to skip, if you want to do this.

Once you have done this, click the "SaveAs" button, and name the import
specification. From then on, when you use the TransferText method on a file
with this particular format, use this ImportSpecification.
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



"(E-Mail Removed)" wrote:

> Hello
>
> The code below imports a csv-file into a table.
> For the field F18 I don't get what I want.
> In the csv-file 'F18' is of a 'general' format. I don'g get the data
> correctly, it has been transformed into a 'time format'. Even if I add
> the ALTER TABLE ALTER COLUMN statement to change the data into numbers
> doesn't help. Now I have some blancs where there even shouldn't be
> one.
>
> Can somebody help?
>
> DoCmd.DeleteObject acTable, "TBL_Import_TPXP_Radi_College_Newcsvfile"
> DoCmd.TransferText acImportDelim, ,
> "TBL_Import_TPXP_Radi_College_Newcsvfile", "X:\TRANSIT60\AFTP
> \USPB1815\RADICOL\NEW.CSV", False, ""
>
> DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
> ALTER COLUMN [F18] number"
>

 
Reply With Quote
 
geert.van.ransbeeck@telenet.be
Guest
Posts: n/a
 
      13th Mar 2009
I still don't get it.
When I import it manually with the GetExternalData wizard it works.
But then when I do it by the TransferText -mode it doesn't work.
As proposed by Dale I saved the 'import specification' as
'Import_New_CSV' and mentioned it with the statement below.

DoCmd.DeleteObject acTable, "TBL_Import_TPXP_Radi_College_Newcsvfile"
DoCmd.TransferText acImportDelim, Import_New_CSV,
"TBL_Import_TPXP_Radi_College_Newcsvfile", "X:\TRANSIT60\AFTP
\USPB1815\RADICOL\NEW.CSV", False, ""


DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
ALTER COLUMN [F1] text"
DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
ALTER COLUMN [F18] double"
DoCmd.RunSQL "UPDATE TBL_Import_TPXP_Radi_College_Newcsvfile SET
TBL_Import_TPXP_Radi_College_Newcsvfile.F1 = Right('000000000000' &
[TBL_Import_TPXP_Radi_College_Newcsvfile]![F1],12);"


Can anybody help? Thanks a lot!
 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      13th Mar 2009
You didn't do what I told you to do.

1. Get rid of the line that reads:

Docmd.DeleteObject acTable, "tbl_import_TPXP_Radi_College_Newcsvfile"

Then, go into that table in design view and set the appropriate field data
types.

If you must, add a line of code that deletes all of the values from that
table:

currentdb.execute "DELETE * FROM tbl_import_TPXP_Radi_College_Newcsvfile"

2. When you created the import specification, did you select the various
fields (1 and 18) and set their data types to the appropriate settings? If
not, do that as well

3. Now run the TransferText command, importing the data into the saved table

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



"(E-Mail Removed)" wrote:

> I still don't get it.
> When I import it manually with the GetExternalData wizard it works.
> But then when I do it by the TransferText -mode it doesn't work.
> As proposed by Dale I saved the 'import specification' as
> 'Import_New_CSV' and mentioned it with the statement below.
>
> DoCmd.DeleteObject acTable, "TBL_Import_TPXP_Radi_College_Newcsvfile"
> DoCmd.TransferText acImportDelim, Import_New_CSV,
> "TBL_Import_TPXP_Radi_College_Newcsvfile", "X:\TRANSIT60\AFTP
> \USPB1815\RADICOL\NEW.CSV", False, ""
>
>
> DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
> ALTER COLUMN [F1] text"
> DoCmd.RunSQL "ALTER TABLE [TBL_Import_TPXP_Radi_College_Newcsvfile]
> ALTER COLUMN [F18] double"
> DoCmd.RunSQL "UPDATE TBL_Import_TPXP_Radi_College_Newcsvfile SET
> TBL_Import_TPXP_Radi_College_Newcsvfile.F1 = Right('000000000000' &
> [TBL_Import_TPXP_Radi_College_Newcsvfile]![F1],12);"
>
>
> Can anybody help? Thanks a lot!
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing 33 fields into a 58 field table (and changing data order tstew Microsoft Access External Data 3 22nd Sep 2009 10:12 PM
Changing Date format when Importing TXT file =?Utf-8?B?U0lUQ0ZhblRO?= Microsoft Access 2 29th Mar 2007 03:16 PM
Changing format in task fields =?Utf-8?B?bWFjZGFk?= Microsoft Outlook Discussion 1 1st Jun 2005 01:10 PM
Importing Text without changing the Format to Scientific? Terry. Microsoft Access External Data 1 9th Feb 2004 10:24 PM
Converting format fields after importing from Excel Aline Microsoft Access External Data 2 29th Aug 2003 12:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:33 PM.