Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

macro to replace always one selected option

I need to create a macro that basically replace the option "always one selected" for a multi box or list box. Either when the document is opened or when a sheet is opened, I want a selection or the first selection of a field in a multi box or list box to be selected. This field should not allow the selection to be cleared but should allow the user to make another selection from the field.

For example, if I have an employee name as a field in a multi-box, then when I open the document or switch to that sheet, the macro should force a name to be selected. I should not be able to clear the selection because at least 1 name should be selected. HOwever, he user should be able to select another name from the list.

I have never created a macro so I am not even sure where to begin. Any help would be greatly appreciated!

10 Replies
Anonymous
Not applicable
Author

Nicolas,

See another example. Notice thta you must select a value before setting "always one" property.  I mentiioned it in my old post, although without example.

Sub SetOnlyOne
' first, select one value (you have to make sure it always exist after reload
' it may look more complex in real app
set a=ActiveDocument.GetField("A")
A.Select "1"
' set "always one selected"
set a=ActiveDocument.GetField("A")
aSel=a.GetSelectedValues.Count
if aSel=1 then
  set prop = a.GetProperties
  prop.OneAndOnlyOne = true
  a.SetProperties prop
end if
End Sub


The macro can be triggered by "post reload" or "on open"

(I tested it, it worked)

Regards,

Michael