Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need help on macro to select group field value

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

5 Replies
Not applicable
Author

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!

Not applicable
Author

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

Not applicable
Author

I should have added, remove all the calls to MyWriteLog.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Check this URL for solution.

http://community.qlik.com/message/48822#48822

Regards,

Jagan.

Not applicable
Author

This worked for me fantastic. Thanks!