5 Replies Latest reply: Nov 15, 2012 6:00 AM by matthew.bishop RSS

    Need help on macro to select group field value

    Dipesh Patel

      Hi,

       

      I have drill-down group that contains fields from table. Now I am tyring to select that field by running a macro:

      ActiveDocument.Field("Region").Select "EMEA" but it came with an error: Object doesn't support this type of property/method

      another approch

      ActiveDocument.GetGroup("Region").Select "EMEA" but same error

       

      How can make selection of any group field value through macro?

       

      Thanks

        • Need help on macro to select group field value
          Brandon Apperson

          I believe that this can be handled using the following:

           

          Set f = ActiveDocument.Fields("Region")

          f.Select "EMEA"

           

          But to select all values for the region field you could use f.Select "*".

           

          Without seeing your code I cannot help much beyond this.

           

          Hope this helps!

          • Need help on macro to select group field value
            John Overton

            You cannot use select with a group.  Unfortunately, what you are trying to do takes a lot more work.  The basic logic is the get the group, walk the list of possible values to determine the offset between the currently selected value and the one that you want.  Then call "Cycle" to get that value.  This code does pretty much what you need.  Good luck.

             

            sub SetOneDimension(LogFile, DimName, DimValue)

              on error resume next

             

              MyWriteLog LogFile, False, "SetOneDimension - GroupName=" & DimName & ", Dimension=" & DimValue

              set Grp = ActiveDocument.GetGroup(DimName)

              if (Err) then

                MyWriteLog LogFile, False, "SetOneDimension - Error calling GetGroup.  Err: " & Err.Description & " (Num=" & Err.Number & ")"

                Err.Clear

                exit sub

              end if

             

              set GrpProp = Grp.GetProperties

              if (Err) then

                MyWriteLog LogFile, False, "SetOneDimension - Error calling Grp.GetProperties.  Err: " & Err.Description & " (Num=" & Err.Number & ")"

                Err.Clear

                exit sub

              end if

             

              set Dims = GrpProp.FieldDefs

              if (Err) then

                MyWriteLog LogFile, False, "SetOneDimension - Error calling GrpProp.FieldDefs.  Err: " & Err.Description & " (Num=" & Err.Number & ")"

                Err.Clear

                exit sub

              end if

             

             

             

              set Fld = Grp.GetActiveField

              'vs_msgbox("The active field is: "& Fld.Name)

              if (Err) then

                MyWriteLog LogFile, False, "SetOneDimension - Error calling Grp.GetActiveField.  Err: " & Err.Description & " (Num=" & Err.Number & ")"

              end if

              curr_pos=-1

              for i=0 to Dims.Count - 1

                if (Dims(i).Name = Fld.Name) then

                  curr_pos=i

                  'vs_msgbox("Current Match Found at " & curr_pos)

                  exit for

                end if

              next

              'vs_msgbox("Curr Pos is " & curr_pos & " out of " & Dims.Count)

             

              dim_pos=-1

              for i=0 to Dims.Count - 1

                if (Dims(i).Name = DimValue) then

                  dim_pos=i

                  'vs_msgbox("Dimension Match Found at " & dim_pos)

                  exit for

                end if

              next

             

              if (curr_pos >= 0 and dim_pos >=0 and curr_pos <> dim_pos) then

                if (curr_pos < dim_pos) then

                  cycle_cnt = dim_pos - curr_pos

                elseif (curr_pos > dim_pos) then

                  cycle_cnt = dim_pos + Dims.Count - curr_pos

                end if

                'vs_msgbox("Cycle " & Dimname & " by " & cycle_cnt & " to set the active dimension as " & DimValue) 

                Grp.Cycle cycle_cnt

                if (Err) then

                  MyWriteLog LogFile, False, "SetOneDimension - Error calling Grp.Cycle.  Err: " & Err.Description & " (Num=" & Err.Number & ")"

                end if

              end if

             

            end sub