Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: How to write a program In Microsoft Access to convert "test.txt" -- Please help me!!


Message #1 by "moin" <moin_ny@y...> on Sat, 1 Sep 2001 05:33:07
I have to write a program In Microsoft Access to convert "test.txt" to a 

tab delimited file.

All fields must be trimmed of extra spaces. 

Include a form to specify the input and output and a button to run the 

conversion.



Can anyone help me out with this please? Any code example or advice would 

be greately appreciated!!

Thanks you so much in advance.



moin
Message #2 by Brian Skelton <brian.skelton@b...> on Sat, 1 Sep 2001 16:32:25 +0100
Hi Moin



This will (should - not tested) work if:



1) You're using DAO and not ADO

2) The file format and number of fields in your fields don't change

3) Your files have a header row with field names in them.



Your form has two text boxes (txtInFile and txtOutFile) and the 

following code runs from a command button.



To set up the 'Predefined tab export'  specification, import your text 

file by hand into a table. Then export it, and click on the 'Advanced' 

button when the wizard is displayed. Set your {tab} delimiter and the 

click on the 'Save As' button. Give the export specification the same 

name as you'll use in the code.



Private Sub cmdProcess_Click()

Dim dbCurrent As Database

Dim rstTemp As Recordset

Dim fldsTemp As Fields

Dim fldTemp As Field



    DoCmd.TransferText acImportDelim, , "tbltemp", Me![txtInFile], True

   

    Set dbCurrent =3D CurrentDb

    Set rstTemp =3D dbCurrent.OpenRecordset("tblTemp")

    Set fldsTemp =3D rstTemp.Fields

   

    rstTemp.MoveFirst

    dowhile Not (rstTemp.EOF)

        For Each fldTemp In fldsTemp

       

            rstTemp.Edit

                fldTemp =3D Trim(fldTemp)

            rstTemp.Update

        Next

        rstTemp.MoveNext

    Loop

   

    DoCmd.TransferText acExportDelim, "predefined tab export", 

"tbltemp", Me![txtoutfile], True

   

    rstTemp.Close

    Set rstTemp =3D Nothing

    Set dbCurrent =3D Nothing

    Set fldsTemp =3D Nothing

    Set fldTemp =3D Nothing

   

End Sub



-----Original Message-----

From:	moin [SMTP:moin_ny@y...]

Sent:	01 September 2001 06:33

To:	Access

Subject:	[access] How to write a program In Microsoft Access to convert 

"test.txt" -- Please help me!!



I have to write a program In Microsoft Access to convert "test.txt" to a 



tab delimited file.

All fields must be trimmed of extra spaces.

Include a form to specify the input and output and a button to run the

conversion.



Can anyone help me out with this please? Any code example or advice 

would

be greately appreciated!!

Thanks you so much in advance.



moin






  Return to Index