Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi I am trying to remove the always one selected on a list box when I leave a sheet and re-activate when I go back to the sheet.
I have the following sub and have the first one in the trigger for on opening sheet and the second one for when you leave the sheet.
It is getting rid of the always one selected when I leave the sheet but it is not re-applying when I go back to it.
Any help would be great
Thanks
Sub Alwaysoneselected
Set QvObj = ActiveDocument.GetSheetObject ("LB202")
Set MyField = QVObj.GetField
Set FieldProp = MyField.GetProperties
FieldProp.OneandOnlyOne = True
MyField.SetProperties FieldProp
End Sub
Sub RemoveAlwaysoneselected
Set QvObj = ActiveDocument.GetSheetObject ("LB202")
Set MyField = QVObj.GetField
Set FieldProp = MyField.GetProperties
FieldProp.OneandOnlyOne = False
MyField.SetProperties FieldProp
ActiveDocument.ClearAll True
End Sub
Your need a MyField.Select statement before the OneandOnlyOne = False line.
Since there is no value selected before you call macro 'Alwaysoneselected', the 'OneandOnlyOne' won't work. So try to use a trigger to select a value from the list first then call the macro to enable the property. Check the sample attached.
Or, yes (as m w says above), simply add one more line to replace the additional trigger, like:
Set QvObj = ActiveDocument.GetSheetObject ("LB202")
Set MyField = QVObj.GetField
Set FieldProp = MyField.GetProperties
ActiveDocument.Fields("YourField").Select "AValue"
FieldProp.OneandOnlyOne = True
MyField.SetProperties FieldProp
I could suggest using a triggers .
Go to sheet Properties > Triggers > Onactivatesheet
> Onleavesheet
is it the requirement to go with Always one selected value?? because using sheet trigger can easily select and deselect a field value ,
Hi,
You can use sample macro from this link for this purpose in the Onactivatesheet and Onleavesheet triggers.