How to enter text into a dialog textbox via macro?

Following is my code that declares variables that should allow me to access a textbox named “TextField1” in a dialog box named “Dialog_location”

Sub StartDialog_show_loc

Dim oDoc as Object
Dim  oLib As Object, myDlg As Object, oDlgField As Object

oDoc = ThisComponent
DialogLibraries.LoadLibrary("Standard")
oLib = DialogLibraries.GetByName("Standard")
myDlg = oLib.GetByName("Dialog_location")
oDlg = CreateUnoDialog(myDlg)
oDlgField = oDlg.GetByName("TextField1")

oDlgField.text = Anat_butt
oDlg.execute()


End Sub

When this bit of code runs, I get “Property or method not found: GetByName” and the line of code “oDlgField = oDlg.GetByName(“TextField1”)” is highlighted in the BASIC IDE. Is there a problem with my syntax here, or am I going about this completely wrong?

Thanks in advnace
docbda

In order to access a text box (or any other control for that matter) in a dialog you have to get the control first, and then get the model for the control. Aferwhich, you can set the properties of the control model. The “model” is essentially all of the properties that you can set for a dialog control if you were in the dialog window of the LO Basic IDE. In the case of my text box, the property that I want to set is “text”. Of course, different controls have different properties that can be set. You have to look up the properties that can be set for the given control you are working with. A list of the properties for the control that you are working with is likely included in the tables of chapter 18 in Open office.org “Macros Explained” by Andrew Pitonyak. You can easily find this in pdf format if you Google it.

Below is the required syntax:

Sub StartDialog_show_loc(anatomy)
    
    Dim oDoc as Object
    Dim  oLib As Object, myDlg As Object, oDlgField As Object, oTBmodel As Object
    
   REM set oDoc object variable to the current document 
oDoc = ThisComponent 
   REM Load "Standard" library
DialogLibraries.LoadLibrary("Standard") 
    REM Load dialog libraries
oLib = DialogLibraries.GetByName("Standard") 
     REM set myDlg to dialog named "Dialog_Location"
myDlg = oLib.GetByName("Dialog_location") 
     REM create Uno object "myDlg" which creates the dialog
oDlg = CreateUnoDialog(myDlg)
     REM obtain the control and control model
oTBmodel = oDlg.GetControl("TextField1").getModel() 
     REM set the text property of the text box to the string variable "anatomy"
oTBmodel.Text = anatomy 
     REM execute the dialog
oDlg.execute() 
    
    End Sub