0 Replies Latest reply: Jul 21, 2017 12:17 PM by Amanda Welt RSS

    Macro to add "Clear Field" actions to a Text Object

    Amanda Welt

         Hi all -

       

      I'm attempting to write a macro that will add a "Clear Field" action to a specified text object for every field that exists within a particular table in my qvw (the Calendar table in the below example).  The below code works in the following scenarios:

      1. I create a new text object and run the macro.  The initial run of the macro works, however subsequent runs add only the first and last field in my table.

      2. I add a message box to the code below to display k for each value of the index

      3. I run this macro via an external program that opens the QVW, runs the macro, and then closes the QVW.

       

      Does anyone have any thoughts on additional things to try?

       

      sub ButtonActionsFields

      set flds=ActiveDocument.GetFieldDescriptions

      fldcount=0

      for i=0 to flds.count-1

      set fld=flds.item(i)

      if not fld.IsSystem then

        fldTableCount=ubound(fld.SrcTables)+1

        tables=fld.SrcTables

        fldTables=""

        for j=lbound(tables) to ubound(tables)

         fldTables=fldTables & tables(j) & ";"

        next

      end if

      if instr(fldtables,"Calendar") then

        fldcount=fldcount+1

        'k=fldcount-1

        call AddClearFieldAction2(fld.name)

      end if

      next

      end sub

       

       

      sub AddClearFieldAction2(field)

        set Button1= ActiveDocument.GetSheetObject("TX1001")

        set prop1 = Button1.GetProperties

        set actions1 = prop1.Layout.ActionItems

        actions1.Add

        k = actions1.count - 1

        'msgbox(k)

        'ActiveDocument.GetApplication.Sleep 2000

        actions1.Item(k).Type = 36

        actions1.Item(k).Parameters.Add

        actions1.Item(k).Parameters.Item(0).v = "[" & field & "]"

        Button1.SetProperties prop1

        set Button1 = nothing

        set prop1 = nothing

        set actions1 = nothing

        set k = nothing

      end sub