How to get content from field

306 Views Asked by At

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.

so the database looks like this.

ID_ZIP  ZIP  CITY
1      97425 Les Avirons
2      82289 Toto

In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.

So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.

I tried this

Sub getZip

Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
 
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"

End Sub

But it returns an error on the Toto = Form.GetByName("ZipCode") line.

1

There are 1 best solutions below

0
On

The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:

  1. Create Form in Design View
  2. Use the List Box tool (is that what you mean by "select"?) and create a control.
  3. Cancel out of the wizard if it pops up.
  4. Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
  5. Set the Name to "ZipCode" (without quotes).
  6. Save and close the form.
  7. Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.

A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.