I am working on a Windows 10 LibreOffice 7.1.2 database. the ODB file along with a folder and four subfolder with 4 graphic in them can be found here,
I am working on the form “Form Setup” . I am writing a macro to populate the BirthCity textbox based on the item selected in the birthCitylst listbox. Here is the code I am using the “Mouse button pressed” event of that listbox.
Here is the code.
Sub pick_city_list Dim oForm as Object Dim countryText as string Dim cityList as Object Dim cityBox as Object Dim oCountryList as Object Dim oCountryBox as Object Dim idebugCode as integer Dim DatabaseContext As Object Dim DataSource As Object Dim Connection As Object Dim InteractionHandler as Object Dim Statement As Object Dim ResultSet As Object Dim Names As Object Dim I As Integer REM Determine if the countrylist text box has a value oForm = ThisComponent.DrawPage.Forms.GetByName("dsPhotoInfo") oCountryBox = oForm.getByName("birthCountry") IF oCountryBox.text <> "" THEN ' Connect to database DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext") Names = DatabaseContext.getElementNames() For I = 0 To UBound ( Names()) MsgBox Names(I) Next I DataSource = DatabaseContext.getByName("Bibliography") If Not DataSource.IsPasswordRequired Then Connection = DataSource.GetConnection("","") Else InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler") Connection = DataSource.ConnectWithCompletion(InteractionHandler) End If ELSE Print "No Country" EXIT SUB ENDIF End Sub
I got the database access portion of the code from the Apache OpenOffice help pages here:
When I first added the
"DatabaseContext = createUnoService(“com.sun.star.sdb.DatabaseContext”) lines I kept getting and errore saying that no such object at the "DatabaseContext.getbyName() line. So I did more Googling and found this page.
I added the code for display all the database names
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
Names = DatabaseContext.getElementNames()
For I = 0 To UBound(Names())
and got a dialog that one called “Bibliography” As you can see I inserted that in the DatabaseContext.getbyName() call and now things are working up this point.
My question is where did “Bibliograpy” come from. I do not recall naming anything with that when I created the database, the ODB file the tables or the forms. It is as though LibreOffice just pulled it out of thin air!!!.