 |
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 11th, 2004, 10:49 AM
|
Registered User
|
|
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Export table to txt in Access XP
Hello All. I hope someone here can give me some pointers.
I'm trying to send/export to file 1 line header, 2 line detail and 1 line trailer using Access XP.
How do I do this?
I'been looking around some samples but I couldn't get it to work.
Is there a kb or site where I can look up for this?
Any help would be very very much appreciated.
Claudio.
|

May 12th, 2004, 09:33 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Is that you are trying to save your Access table as a text file?
I think you got to open the Database, from File menu you can look for something like "EXPORT" or "Save as" and can save that in txt format by selecting the FILE TYPE in the popping DIALOG there.
I am not sure about the options in Access XP, but this is what followed in its earlier versions. this may guide you to do that.
Hope that helps.
Cheers!
-Vijay G
|

May 12th, 2004, 10:25 AM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
As additonal resources can you use the transfertext macro option to export your databases data.
The macro and event procedure can be found in the access help files
TransferText Action
You can use the TransferText action to import or export text between the current Microsoft Access database (.mdb) or Access project (.adp) and a text file. You can also link the data in a text file to the current Access database. With a linked text file, you can view the text data with Access while still allowing complete access to the data from your word processing program. You can also import from, export to, and link to a table or list in an HTML file (*.html).
Note If you link to data in a text file or an HTML file, the data is read-only in Access.
|

May 13th, 2004, 02:02 PM
|
Registered User
|
|
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
First of all, thanks for taking the time to respond.
Actually, I was hoping I would get the exporting through coding (form)
This is what I´ve got so far.
Private Sub Comando1_Click()
Dim filesys
Dim outputfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set outputfile = filesys.CreateTextFile("c:\output.txt", True)
outputfile.writeline "Field1" & vbTab & "Field2"
outputfile.Close
How can I link the writeline command with a table?
Commented out are some examples I already tried.
'''DoCmd.OutputTo acOutputTable, "TABLA1", acFormatTXT, "Employee.TXT", True
'''DoCmd.TransferText acExportDelim, "tabla1", "C:\April.txt"
'''Dim acAccess As Access.Application
'''Set acAccess = New Access.Application
'''acAccess.OpenCurrentDatabase "C:\Documents and Settings\Sheltonwade\Desktop\'.Net Lab'\Lab Examples\Labfiles\Lab111\Northwind.mdb", True
'''acAccess.DoCmd.TransferText acExportDelim, TableName:="Orders", FileName:="C:\Documents and Settings\All Users\Desktop\Exported File.csv", hasfieldnames:=True
End Sub
And this is what I need.
HEMPRESA 200404301141040001 .
D 000000000000020017999RI30708193670 .
D 000000000000020017999RI30708193670 .
D 000000000000020017999RI30708193670 .
T00009 .
Where:
The first line is a header (from a table)
The second, third and fourth line are details (from a another table)
The fifth line is a trailer (another table?)
I was hoping I could merge all three files in one (Even in MSDOS I couldn´t pull it up in Access)
As you can see I´m a newbie !! :)
Any help you can give me will be great !
Claudio.
|

May 14th, 2004, 01:55 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could you possibly use a recordset? such as (and this is only a quick example from the top of my head - add to that I've been using Acc97 all day, so I'm in DAO mode, not ADO, and it's late on a Friday afternoon)
Code:
Function fExport()
Dim rst as DAO.Recordset
Set rst = CurrentDB.OpenRecordset("YourHeaderTable")
Open "C:\YourFile.txt" For Output As #1
Print #1, rst("YourHeaderField")
Set rst = CurrentDB.OpenRecordSet("YourDataTable")
Do Until rst.EOF
Print #1, rst("DataField1") & " " & rst("DataField2")
Loop
Set rst = CurrentDB.OpenRecordSet("YourFooterTable")
Print #1, rst("YourFooterField")
Close #1
End Function
It might not be what you're after, but it should give you an idea
I am a loud man with a very large hat. This means I am in charge
|

May 14th, 2004, 01:36 PM
|
Registered User
|
|
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm all ears about recordset. But I'm getting the following error
"Compilation error
Type has not been defined by the user" (translated text)
This is the code I'm using:
Private Sub Comando3_Click()
Call fExport(1)
End Sub
Function fExport(inttype As Integer)
Dim rst As DAO.Recordset
Dim rst
Set rst = CurrentDb.OpenRecordSet("tabla1")
[...]
Any ideas from the gurus?
Not in the face!! This is my first program. :D
|

May 16th, 2004, 04:37 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ah, as I suggested - I was in my Acc97/DAO mindset.
To use that code in Acc2k or XP, you'd have to set a reference to DAO, which isn't there by default after 97.
(In the VB window, Tools>References > Microsoft DAO 3.6 Object Library)
The other way to get around that would be to re-write that code using ADO
Steven
I am a loud man with a very large hat. This means I am in charge
|

May 20th, 2004, 03:54 PM
|
Registered User
|
|
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you Steven
Sorry for the delay.
This code helps me out a lot.
Althou I had to remove de do until--loop function
because when I tried it out, it started adding the same table
over and over again until I stopped it.
Again, thanks.
|

May 20th, 2004, 06:31 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ah - of course I left out the MoveNext bit - i.e:
Code:
Do Until rst.EOF
Print #1, rst("DataField1") & " " & rst("DataField2")
rst.MoveNext
Loop
I am a loud man with a very large hat. This means I am in charge
|

May 24th, 2004, 08:02 AM
|
Registered User
|
|
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Steven, sorry, but it doesnt work.
it doesnt matter, I will get it eventually.
no big deal for now
this is where you can help me out
I've been looking at the help files and nothing
I'm looking for a command to take two fields from a table
and add/update these values to another table wich already has these
fields.
ie
I get a file. a txt and I read it, one of the fields has a
unique field and I use this field to name a table. in that table I want all the fields from the record in the .txt
The question is:
What command would *somebody intelligent* use to copy from a table (when I read the file, it will get stored in a table) to another table (named after the unique name)
(I've already seen the copyobject. no use. maybe i could use some of the code you already shared. write some field to file and read it to store to table....i'll work on this in the meantime.....)
Sorry if this gets complicated,
I'll explain better if needed.
Thanks for any input
Claudio.
|
|
 |