Create a txt from a table db with VBA

omaggi

Registered User.
Local time
Today, 07:47
Joined
Oct 19, 2009
Messages
43
Hi Everyone.
In my project I tried when I clicked on a button, to create a file.txt with all the informations that contains a table of my db.

Here my code:
Private Sub bBackup_Click()
Dim SQL_query As String
Dim Path As String
Path = "c:/test.txt"
SQL_query = "select * from valori15min into outfile " & Path
DoCmd.RunSQL SQL_query
End Sub


When I try to run, I have an error that say I have an error with the sintax of the FROM (run-time error '3131').

Anybody can help me or suggest me another way to do this job?

Thx a lot, greetings
 
You have to use "Docmd.Transfertext" not a query...

Your query will or would with the correct syntax try to create a table... which you dont want.

Find the transfertext in the help and see if you can find your answers there.
 
Thx, works fine with Docmd.transfertext.
Now I tried to do the "restore" (import from txt) but I have some problems...

My code:

DoCmd.TransferText acImportDelim, , "tableName", "c:\test.txt"

The error said that a value "F1" is not in my table... :(
 
in Transfertext you can specify a "template" or "SpecificationName", you can make this specification doing the import once manualy (file> Import) and saving the specification.

What is going on is that access is trying to think for itself (no specification given) and making the wrong choices... so you have to make the choises for it.
 
thx works greatly now!

have a good night! greetings!
 

Users who are viewing this thread

Back
Top Bottom