p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vb_howto thread: CSV File


Message #1 by philip.moh@a... on Fri, 25 May 2001 18:04:46 +0800
the command for Transfter text is :

docmd.transfterText transftertype, specificationName, TableName, FileName,
HasFieldsName

You need a specificationName, which is required if you are using CSV(comma
separated files).
In CSV files where the columns are not aligned, but placed next to each
other. Each column is separated from the next by a special character(usually
a comma). If is not a comma you need to specify what it is.
So u need to create a specification to tell Access how the text file is
structured

So:
1. Make sure you are in the Tables view of the database window, and select
Table.
2. From the file menu select import
3. On the import dialog, select Text Files in the Save as Type combo box at
the bottom of the screen.
      ps: don't worry about the file name , since you're not actually going
to export anything
4. click the save button. this will start the import text wizard. Don't run
anything through any of the wizard.
5. click the advanced button.
6. the two important items here are the field Delimiter and the text
qualifier.
The field delimiter is what the fields will be separated by(usually a
comma). The text qualifier is what is placed around the text fields
and is usually double quotation marks. Well, do your specifications.
7. Save this specification by clicking the save as...........button. Give it
a name of SthgDelimited.
8.press the ok button to return to the Import Text Wizard, and then click on
the cancel to close it.

your vb behind a command button should be sthg like:

DoCmd.TransferText acimportDelim, "SthgDelimited", "Table.mdb",
"c:\MyData.txt", True

msgbox "Your details imported"


ps: 'true' means that the source of data has field names as the first row.

mike wilson
----- Original Message -----
From: <philip.moh@a...>
To: "VB_Howto" <vb_howto@p...>
Sent: Friday, May 25, 2001 4:04 AM
Subject: [vb_howto] CSV File


> Does anyone know how to read the data in the CSV file and then create and
> write it data to the other new text file??? Please help...
>
>
>
> > -----Original Message-----
> > From: Yoel Pedersen [SMTP:y.pedersen@g...]
> > Sent: Friday, February 09, 2001 1:23 PM
> > To: VB_Howto
> > Subject: Re: TTX Files
> >
> > Yes, it's pretty easy.
> >
> > Private Sub_SaveATxtFile()
> >
> > Dim intFileNumber As Integer
> >
> > intFileNumber = FreeFile
> >
> > Open "C:\My Documents\Sample.txt" For Output As #intFileNumber
> >
> > Print #intFileNumber, "This is some text"
> >
> > Close #intFileNumber
> >
> > End Sub
> >
> > This should cause a txt file called Sample.txt to be created in your
> > document folder.
> >
> > Sincerely, Yoel Pedersen


  Return to Index