How to link to a specific dialog form with Calc Macro ListBox specific item

Hi all, I am quite new to this OpenOffice Calc Macro codes. Currently, I am working on a project and along the way, I faced this problem. For example, a user selects one item from the Listbox (lb_tables). The selected item is to be linked with its particular Form (dialog). Thus, when a user clicks on that item, the respective form is to appear. But I can’t seem to make it work. Here are my codes. Please help me!

Sub read_lb_tables

Dim DialogField as Object
Dim seleclItem 

DialogLibraries.loadLibrary( "Standard" )

'loadDailog needs the library and dialog names 

openDialog = createUnoDialog (DialogLibraries.Standard.create_dialog)

DialogField= openDialog.getControl("lb_tables")

selectItem.String = DialogField.getSelectedItem()

if selectItem = "Article_meeting" Then
 
article_meeting_dialog

End if

End Sub

Thank you for the answer. But, it is the answer I am looking for. I will explain with an example. For example, I put different tables in a database. And I retrieve those tables by using Calc macro i.e. I take the table names and put them in the listbox of a dialog. Then, when the user clicks on the particular table name, that will open another dialog which will let user to fill in data into Database for that particular table details. But, when I run the code, I got an error “variable not defined” for this line of code “selectItem.String = DialogField.getSelectedItem()” . Here is the code generate the table list.

Sub create_dialog (db as Object)
db = connect_to_database("formpopulationdatabase")
Dim d as Integer
Dim dbTables as Object
Dim dbTableNames 
Dim opText as String
Dim DialogField as Object
dbTables = db.getTables
dbTableNames = dbTables.getElementNames
DialogLibraries.loadLibrary( "Standard" )
'loadDailog needs the library and dialog names 
openDialog = createUnoDialog (DialogLibraries.Standard.create_dialog)
DialogField=openDialog.getControl("lb_tables")
For d = 0 To UBound(dbTableNames())
opText = dbTableNames(d) ' + chr(10)
DialogField.additem(opText,0)
Next d
openDialog.execute() 
disconnect_from_database(db)
End Sub

Please do not use an answer to respond. Answers are to respond to original question. Instead use a comment. If this is not enough space, Edit original question adding the additional information an d note it as edited information>

Thank you, Sir. I am quite new here. I will keep note of this. ^ ^

Hello,

Here is how to open a dialog:

DialogLibraries.LoadLibrary("Standard")
myDlg = CreateUnoDialog(DialogLibraries.Standard.DIALOG_NAME)
myDlg.Execute()
myDlg.dispose()

However, the manner in which your question is presented seems to have nothing to do with dialogs at all.

If in fact the user is selecting a list box item ( appears to be a list of tables - how is it generated?) and you want to open a view of this table, a dialog is not the manner to accomplish this (although it can be done but more coding). If this is really the case, the probable way to do this is to create all the views (table grid control?) and forms for each table involved then hide/reveal the appropriate grid/form based upon the selection (have done similar using sections).

Don’t know what use this is for. Have not seen anyone request something like this. Maybe some insight as to the reason or why it is needed?

There are some links to samples in my answer here → base: how to make a form that relates to different possible tables

Edit 2018-06-01:

Yes, my explanation above still applies. However if you insist on using dialogs you have a lot of work ahead.

Dialogs are NOT data aware! You cannot access tables in the dialog - reading OR writing. All you have there is fields. You have to move data from and to tables using coding through macros (they are NOT Calc macros - just macros). You can access fields in a dialog before displaying the dialog - see my answer in this post → How to enter text into a dialog textbox via macro?. So that answers you current question.

Now for the user to enter data, you must have the dialog be a global variable; in your case that would be openDialog. Now you openDialog.Execute so the dialog is presented to the user. The user enters data and signifies completion by pressing a button on the dialog which triggers an event which triggers another macro written by you. This macro gets the info entered by the user from the field using the global variable and you must the update the appropriate field in the appropriate table. This continues until the dialog is closed.

A lot of work because code needs to be written for each and every table you are going to do this for. Also depending upon just what is being updated in each table you may need to have different dialogs for each table. You can get around this by coding your own dialog and placing appropriate fields in the dialog using a macro. For this see my sample in my question here → Looking to create grid (not table) control on Base form. There is another sample & code (basic & python) in my question here → Dialog problem when using Python.

Edit #2 2018-06-01:

Have put together a quick sample of hiding/revealing grids based on different tables depending upon list box selection.

Sample ----- MultiTableSelectionEntry.odb

Neither of the two methods are preferable. You should simply have a different form for each table you are attempting to modify.

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.