Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

get text field value

Hi,

I have an odt writer document with 2 input text fields (added with the form designer toolbar). I manually type text into one of the fields. I copy/pasted a macro to see if I could grab the text within the input field but haven't had any luck. This is the macro in Basic:

REM Author: Heike Talhammer
REM Modified: Andrew Pitonyak
Sub EnumerateFields
  Dim vEnum
  Dim vVal
  Dim s1$, s2$
  Dim sFieldName$, sFieldValue$, sInstanceName$, sHint$, sContent$

  vEnum = thisComponent.getTextFields().createEnumeration()
  If Not IsNull(vEnum) Then
    Do While vEnum.hasMoreElements()
      MsgBox "In loop"
      vVal = vEnum.nextElement()
      If vVal.supportsService("com.sun.star.text.TextField.Input") Then
        sHint=vVal.getPropertyValue("Hint")
        sContent=vVal.getPropertyValue("Content")
        s1=s1 &"Hint:" & sHint & " - Content: " & sContent & chr(13)
        'change the content
        vVal.setPropertyValue("Content", "My new content")
        ThisComponent.TextFields.refresh()
      End If

      If vVal.supportsService("com.sun.star.text.TextField.User") Then
        sFieldName  =vVal.textFieldMaster.Name
        sFieldValue = vVal.TextFieldMaster.Value
        sInstanceName= vVal.TextFieldMaster.InstanceName
        s2 = s2 & sFieldName & " = " & sFieldValue & chr(13) & "InstanceName: " & sInstanceName & chr(13)
        'new value for textfield
        vVal.TextFieldMaster.Value=25 
      End If
    Loop
    MsgBox s1, 0, "=== Input Fields ==="
    MsgBox s2, 0, "=== User Fields ==="
  End If
  ThisComponent.TextFields.refresh()
End Sub

When I run this macro I just get 2 blank message boxes with the titles "=== Input Fields ===" and "=== User Fields ===". (the message "In loop" is NOT displayed)

What am I doing wrong?

Thanks