Export table data to text file

  • Thread starter Thread starter Gina
  • Start date Start date
G

Gina

Hi.

My little access 2k prog should be able to exchange data between 2
standalone pcs placed at different locations. I thought that exporting the
data to a number of text files would be the best way to handle it.
I've tried a macro using MS-DOS text .... but it has headers in it ... which
is probably the reason for importing problems on the 2nd machine's program.
Some of my tables contain autonumber fields ( but this obviously wasn't the
reason for the clash)
Thought I better use vba...
exporting - on button click - and the created text files are send directly
to a floppy disc.
This may be the best option - as the users are (unfortunately) not used to
use computers at all.
I would be very grateful if someone could give me a hand on how to start.

Thanks in advance
Gina
 
Hi Gina,



Open Me.txtFileName.Text For Input As #1

Print #1, myFirstField & "," & mySecondField

this process will export to a comma seperated file, if the fields are
strings, they need to be wrapped e.g.

Print #1, chr(34) & myFirstField & chr(34) & "," & chr(34) &
mySecondField & chr(34)

looping through all the record you want to export, the use of floppy
disks is a real pain, is there no connectivity between the computers.

There are many ways to skin this one, this is just one of them if you
have any problems post here and I will try to help some more.


Regards

Alex
 
Alex, thanks a lot !!

well ... that is exactly what I am looking for .... with a comma as
separator!!

Gina
 
Alex....

as you might have foreseen ... I am here again.
well .... at the moment the two machines aren't connected .... but maybe I
should convince them doing some WLan thing ....

anyway I think to export some data to a simple text file - I would like to
do this at least once!!

and here is my first problem...
ERROR: Wrong file modus (runtime err 54) at line -->

__________________________
Private Sub cmdExportText_Click()
Dim DT, ST, SQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb

DT = "tbl_MaterialList"
ST = "tbl_MaterialList"
SQL = "SELECT tbl_MaterialList.Material, tbl_MaterialList.Use,
tbl_MaterialList.Price FROM tbl_MaterialList"

Set rs = db.OpenRecordset(SQL)

Open CurrentProject.Path & "\" & ST & ".txt" For Input As #1

Do While Not rs.EOF
--> Print #1, Chr(34) & rs("Material") & Chr(34) & "," _
--> & Chr(34) & rs("Use") & Chr(34) & "," _
--> & rs("Price ")
Loop

End Sub

_______________________

Where am I going wrong ???

Gina
 
Back
Top