[Solved] Accessing the document's data sources
[Solved] Accessing the document's data sources
I am working with base and i need to write a few macros that take information from the tables and outputs it, and does calculations etc. Before all I needed to do was just tie UI forms to a filter builder, that got working thanks to Drew! But now I need to actually work with the data, not to mention be able to print it out and make a pager for it since the size of the output can get large. But I found that in order to use rowsets and queries based on my tables I had to register the base file as a data source in oo options. This may be an incorrect statement, maybe I typed something wrong, so if so please tell me. If not, then the problem with doing it that way is if the file ever gets moved, then the user has to go re register the file as a data source in oo options! Or is this also not the case? Am I missing something? So what im looking for is a way to get access to the current files datasource(s). I tried doing something like this.datasource or something, no avail. Anyone got any pointers?
- DrewJensen
- Volunteer
- Posts: 1734
- Joined: Sat Oct 06, 2007 9:01 pm
- Location: Cumberland, MD - USA
Re: Accessing the document's data sources.
Do you mean you want to call this routine from say a button on a form and then get access to the datasource used by that form?
or
You want to refer to an ODB file and get the datasource for it?
Thanks
or
You want to refer to an ODB file and get the datasource for it?
Thanks
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Re: Accessing the document's data sources.
the first one.
- DrewJensen
- Volunteer
- Posts: 1734
- Joined: Sat Oct 06, 2007 9:01 pm
- Location: Cumberland, MD - USA
Re: Accessing the document's data sources.
Alright, let me put together a decent little example for you...won;t take very long...but a bit more then a few minutes..OK
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Re: Accessing the document's data sources.
Wow, I've seen your other posts, how long have you been using this language? You make it seem so easy! Thanks for your help btw.
Re: Accessing the document's data sources.
In BASIC your form document has all the rowset/resultset functionality. You just access your root form with
and then you can use methods like oForm.first, oForm.last, oForm.getString, etc...
To get access to the datasource of your form try and then you can execute queries with
have a nice day.
Code: Select all
oForm=ThisComponent.drawpage.forms(0)
To get access to the datasource of your form try
Code: Select all
oConn=ThisComponent.Parent.DataSource.getConnection("","")
Code: Select all
oResultSet=oConn.createStatement.executeQuery("the sql code goes here...")
Re: Accessing the document's data sources.
Thanks, that did the trick!