views:

2316

answers:

3

Hello,

I have this code:

db = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\baywotch.db5"
TextExportFile = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\Exp.txt"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source =" & db

strSQL = "SELECT * FROM tblAuction1"

rs.Open strSQL, cn, 3, 3

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.CreateTextFile(TextExportFile, True)

a = rs.GetString

f.WriteLine a

f.Close

Which is meant to connect to an access database and produce a tab delimited text file. tblAuction1 is a query in the database, and definitly exists and is not misspelt in any way, but I get an error that it cannot be found or does not exist. When I change it to tblAuction which is the name of the table, I get an error stating f.WriteLine a has been called incorrectly.

edit: I now only get a problem with f.writeline a, saying an incorrect argument has been supplied. I no longer have a problem with tblAuction1

edit: the sql code used for my query:

SELECT tblAuction.article_no, tblAuction.article_name, tblAuction.subtitle, tblAuction.current_bid, tblAuction.start_price, tblAuction.bid_count, tblAuction.quant_total, tblAuction.quant_sold, tblAuction.start, tblAuction.ends, tblAuction.origin_end, tblUser.user_name, tblAuction.best_bidder_id, tblAuction.finished, tblAuction.watch, tblAuction.buyitnow_price, tblAuction.pic_url, tblAuction.private_auction, tblAuction.auction_type, tblAuction.insert_date, tblAuction.update_date, tblAuction.cat_1_id, tblAuction.cat_2_id, tblAuction.article_desc, tblAuction.countrycode, tblAuction.location, tblAuction.condition, tblAuction.revised, tblAuction.paypal_accept, tblAuction.pre_terminated, tblAuction.shipping_to, tblAuction.fee_insertion, tblAuction.fee_final, tblAuction.fee_listing, tblAuction.pic_xxl, tblAuction.pic_diashow, tblAuction.pic_count, tblAuction.item_site_id
FROM tblUser INNER JOIN tblAuction ON tblUser.id = tblAuction.seller_id;
+1  A: 

I think there is something wrong with the spaces in your connection string

Try this:

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = db
cn.Open

HTH

Update: Maybe there is a problem with the access rights to the database? Or the mdb is already opened exclusively by another user (You with your access in design mode)?

danimajo
Hello,Thankyou for your help, but this does not fix the problem. I get error 80040e37 which does not help. should it be dbo.tblAuction1 nstead or something?
Joshxtothe4
The access database is open to anyone and I get the error if access is completely closed. From what I was reading I need to give the full identifier but I am not sure what that means.
Joshxtothe4
2 things to try: add braces to your table: [tblAuction1] and add User Id=admin to the connection string
danimajo
this still made no difference. I get the same error when running a macro from within access
Joshxtothe4
one other ting: try "compact/repair database" in access. a corrupted access db is often the source of all mysterious errors
danimajo
A: 
Tester101
this made no difference
Joshxtothe4
Did you try this using the table name rather than the query?
Tester101
if I do that I get an error on f.writeline a, but I would need the query anyway?
Joshxtothe4
Can you write a simple string to the file? replace the line [f.WriteLine a] with [f.WriteLine "Testing"] and see if you can write anything to the file.
Tester101
yes that works fine
Joshxtothe4
+2  A: 

I have tried to reproduce this on several databases and machines, I can't get your code to fail.

Leaves :

  • a corrupt database, could you please run repair and try again ?
  • Fields in your database that are throwing of the query, I have tried several possibilities but can't find anything that brakes your code. To exclude other things you could try to create a new table and see if your code works on that table.
  • something wrong with your dll's , could you try it on another machine.

Answer (to see how we came to the answer see the comments)

There are unicode characters in your database that writeline does not accept because you created the textfile as ASCI.The characters in this case specifically where ♥♥♥

To make it work:

Set f = fs.CreateTextFile(TextExportFile, True, True)

P.S.

This question was answered earlier using the transfertext macro here As Remou points out this looks like a cleaner solution. To make it work with non-default delimiters is a bit of a pain. First start exporting the query you like to export by right clicking and choose export. In the following dialogs specify the specifications and save these. When creating the macro select the specifications you just saved.

KeesDijk
it is finding tblAuction1 now, but now it states there is a problem with f.writeline a, a bad argument to the procedure
Joshxtothe4
If it is now finding the table, try a normal transfer text. When I provided the code above, it was intended to test your database to see what could be wrong. What operating system are you using?
Remou
What did you do to make it find it ? Repair ? Does it work for tblAuction ? Could you post the sql query for tblAuction1 ?
KeesDijk
I restored an older version of the database, which is interesting because the query was not changed at all, so it must have been damaged a bit. The problem I have now is with the macro not being able to find the filename i specify to write to, and with the vbs having a problem with f.writeline
Joshxtothe4
I am using Windows XP
Joshxtothe4
Can you write the file to a path without spaces ? C:\temp\Exp.txt or something ?
KeesDijk
And still a repair is a good thing to do.
KeesDijk
No, I cannot write the anywhere at all. Although I resaved my specification and now get a problem with the query when trying to make it write to C:\ I have put the sql code used in the main post. I did a repair although it made no difference
Joshxtothe4
I do not think that stackoverflow has the format for this type of problem solving. A more conventional question-and-answer forum would probably be better.
Remou
What do you mean? It is clearly a programming related issue, and while the question is not getting a lot of attention, a lot of people seem to know about it.
Joshxtothe4
I mean that it is not so easy to work through the possible problems when they are not laid out in an orderly question-and-answer format.
Remou
@Remou, I know what you mean, we will pour it in an orderly question-and answer format when there is an answer.
KeesDijk
I am almost out of idea's it must be in the data, could you change the query to "SELECT top 1 * FROM tblAuction1" and if it works, do the higher lower game to find the strange data. The last wild idea is a shortage of hard-disk space ?
KeesDijk
The problem is definitely in the query, as I get "error 2950 syntax error in query: incomplete query clause", I don't understand why it works fine in access, but can not be written to a file? especially in vbscript should it not at least write an empty file?
Joshxtothe4
if I change it to just tblAuction which is the table and not a query, I get this error: 800a0005': Invalid procedure call or argument
Joshxtothe4
You could try a fresh database with one simple table to see if that works. This will eliminate, amongst other things, problems with databases in general on your PC.
Remou
A different table works. I dont think it is a problem with the database or table, just the query access generated. The error would seem to support that?
Joshxtothe4
I do not think so, if your previous statement "if I change it to just tblAuction which is the table and not a query, I get this error: 800a0005': Invalid procedure call or argument"v is true. Access errors are not always accurate.
Remou
Everything I have been trying to research resulted in the query being the problem. Apparently it was common to say the object could not be found if there is a problem with the query
Joshxtothe4
could you rebuild the query ? Maybe first just a few columns ?
KeesDijk
Will check now, I am wondering if the problem is because I want to put in a foreign field?
Joshxtothe4
OK, I have narrowed down the problem to one column. The macro will still not work, but the vbscript file does. Why would a single column becausing this error? It is not because of symbols, it work's fine when I remove a lot of the data
Joshxtothe4
What is the data type of the column ? For text I tried everything I could think of (quotes, tabs, newlines, vbscript continuation character) but I can't make your code fail.
KeesDijk
justtext.., I have put the database up here, maybe you can see something. It is not symbols or such, so I would be unsure what it could be. http://www.yousendit.com/download/TTZuNnFLZy96RTlFQlE9PQ
Joshxtothe4
Now it is easy. In record 940 there are these symbols ♥♥♥ (probably not unicode or something) this breaks the writeline command.
KeesDijk
This could have been easily solved in a similar manner at post #1 regarding TransferText not working.
Remou
I suggest that now the real problem is solved, that the easiest method is used, and that is TransferText. I only supplied the sample code to test whether that worked when TransferText did not.
Remou
The contents of the database will be updated automatically, and I must export the data also automatically. Is there any way to catch the error or strip the symbols?
Joshxtothe4
I can run the vbscript fine now, but I can still not this as a macro, is there a similar way to do that?
Joshxtothe4
Is there any reason transfertext in a macro would have the same problem?
Joshxtothe4
Changing the specification to Unicode UTF-8 did nothing
Joshxtothe4
What problem do you have with the macro ? In your database on my machine it does not give any problems. It just strips the unicode characters.
KeesDijk
How Odd that it works fine on your machine? I tried it on 2 other machines and the same problem. Are you sure the macro is set to execute tblAuction1? I get an error Syntax error in query. Incomplete query clause (Error 3450) when trying to save a stored query.
Joshxtothe4
In your database is a ExportQuery macro, when I run it , it generates the 1.csv just fine. I also created a macro like Remou suggests and it also works (get here: http://drop.io/keesdijk/asset/baywotch ) Could you check in your VB Editor if there are references missing ?
KeesDijk
I changed the path of the file in your macro and it worked, the problem is the macro is not csv delimited, it is outputting a formatted query result not a tab delimited file. When I try and make a macro, as in my original database it gives that error. Try and run macro1 from here: tinyurl.com/5prp6f
Joshxtothe4
To make the macro work you have to make a correct spec file and use it in the macro. (select the query, go to external data and choose export in that dialog you can choose specifications and save the specs you need) see http://drop.io/keesdijk/asset/baywotch1
KeesDijk
Thankyou very much, everything works perfectly now. I would vote you up more if I could.
Joshxtothe4
No need for thanks, it's fun to help. Don't forget Remou, if he could/would have looked at your database his initial solution would have worked.
KeesDijk
Yes of course, many thanks to Remou as well. Just out of curiosity, does it matter that the resulting text files from the vbscript are twice the size of the ones created from the macro?
Joshxtothe4
Actually I am having some problems again :( The Macro will not export unicode symbols, even though I have set UTF-8 in the specification, and the vbscript is not tab delimited..or at least will not import into mysql with \t as a delimiter
Joshxtothe4
We should stop meeting like this. Double the size is from the fact that the macro formats your currency, so all amounts have a euro sign, a comma and two digits. Most Likely you don't want this. You should change the spec probably.
KeesDijk
For the sql import the rowDelimiter is probably the problem. The VBScript can be told what to use as a column and row delimiter :a = rs.GetString(2,,,vbCrLf,"")see http://www.devguru.com/technologies/ado/quickref/recordset_getstring.html
KeesDijk
Should I make a new question perhaps? I am happy with the macro formatting the data, but it is half the size of the vbscript result. Maybe it it not writing everything to file again?
Joshxtothe4
in de spec file change the code file from UTF-8 to unicode. Sizes will almost be the same then (accept for the currency's) , for importing in mysql it would be smart to start a new question.
KeesDijk
It seems to be working :) One last question, I cannot get vbscript to accept carriage returns and newlines as a delimiter, is that not what I should be doing?
Joshxtothe4
this line a = rs.GetString(2,,,vbCrLf,"") sets the rowDelimiter to carriage return line feed in vbscript.
KeesDijk
That did not help..I am unsure as to why. It is a jumbled mess at the moment. It is data already within the mdb file..if I have set the delimiter why would it not be set? Compare http://www.yousendit.com/download/TTZtWmdsT01kMnVGa1E9PQ and http://www.yousendit.com/download/TTZtWmdsT00wVWtLSkE9PQ
Joshxtothe4
There is not much wrong with your text files. Nicely delimited. There only is a column article_desc that sometimes contains a lot of html, that makes it look funny. Also make sure you have word-wrap off when looking at the file.
KeesDijk
I guess it does not matter for importing, but I think it is odd that the macro seemingly generates such niceely formatted text even with the messy html..is it just different tab sizes?
Joshxtothe4
When I change it to Unicode in the macro, the file is 50kb larger..it does not matter but I am curious as to why. Also, if the database will be being changed constantly from a program, maybe it is better to use an external vbscript?
Joshxtothe4