Base - Export data of a stored query in a csv file within a macro

@greb,

Thank you for the sample posted. Will look a bit closer at this today. However I do see a problem with your checking if the database is registered. The registered name is not good for this verification. A database file name is not necessarily the registered name. The registered name can be whatever you want. You cannot have two registered items with the same name even if they are in different locations. The important issue here is the location of the registered Base file. Even if the name is justified (which it is not) if the file was moved, that registration is no longer valid. It need to be registered again and the old should be removed.

See my answer in this post → BASIC+Firebird: How to list non-registered .odb’s ?

Edit:

All else seems to work fine. Only issue I see is the registration.

@Ratslinger,
Thanks again for feedback. Indeed, the ODB file registration checking was problematic and due to error.
I’ve modified it (see today’ edit in my initial post), using indeed the post you referred to.
Thanks.

@Ratslinger

This Calc macro is very useful RegisteredToCSV.ods - but how would I edit the macro to change the delimeter from “,” to “|”?

Thanks.

@MyGrove
There are comments in the code and one leads to this post → Filter Options.
.
There you find that the Field Separator is the first token. In the original code this is a 44 for a comma. If you want to change it to a pipe, the code is 124.
.
Therefore, in Sub Sheets_To_CSV , change this line:

args(1).Value = "44,34,76,1"

to:

args(1).Value = "124,34,76,1"

This was tested and works.

1 Like

Brilliant, thank you.

Edit:
The below response answer a question received directly by mail, mentioning an error:

A Scripting Framework error occurred while running the Basic script Standard.Export.Query_To_CSV.

Message: wrong number of parameters!

while running the exporting to CSV macro in the QueryToCSV.odb file on a Windows computer.


I’m on Linux and have no problem to run the macro correctly.

I just try to run it in a Windows machine and indeed, got an error (but not the one mentioned with scripting framework). It says that the problem come from the line 116 of the macro file :

 oDoc.storeToURL(sURL,args)

Querying what is the output of sURL variable, it seems that there is a problem, with duplication of the folder path in the url output :

file:///C:/Users/user/Desktop/file:///C:/Users/user/Desktop/QueryToCSV_Table1ALL.csv

which is coming from line 108. Modifying to:

 sURL = sODBName & "_" & sQuerySelection & ".csv"

worked for me (ie. it saved the result of the query to a csv file).

I didn’t get the same error message as you, but I hope this might help?

Best.