Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hallo,
like title shows i have little problem with my macro...
The macro is used as a trigger event and should select the Dummy-Serial No if any other SERIAL_NO is selected.
So i write this macro:
Sub SelectDummy
set val = ActiveDocument.Fields("SERIAL_NO").GetSelectedValues
b = val.Count
check = 0
for i=0 to b-1
a=val.Item(i).Text
if a="Dummy" then check=1
next
if check=0 then ActiveDocument.Fields("SERIAL_NO").ToggleSelect("Dummy")
if check=1 and b=1 then ActiveDocument.Fields("SERIAL_NO").Clear
end sub
Which works, but now if i push the Clear-Button, while some SERIAL_NO are selected, all real SERIAL_NO are cleared, but the Dummy stays:(
At this moment there is no possibiltyy to get the field cleared. You can only select another SERIAL_NO and deselect it, then all is cleared...
How can i avoid this?
Thanks for any help,
Sarah
It needs another condition before the error-line:
if val.Count = 0 then exit sub
- Marcus
I'm not sure I understood you right. I Think the macro seems not to cover all possibilities - try this:
Sub SelectDummy
set val = ActiveDocument.Fields("SERIAL_NO").GetSelectedValues
if val.Count = 1 and val.Item(i).Text = "Dummy" then
ActiveDocument.Fields("SERIAL_NO").Clear
else
for i=0 to val.Count - 1
if val.Item(i).Text = "Dummy" then
check = true
exit for
end if
next
if check <> true then ActiveDocument.Fields("SERIAL_NO").ToggleSelect("Dummy")
end if
end sub
- Marcus
Thank u very much for the reply.
"I Think the macro seems not to cover all possibilities" - Yes i think u understand the problem.
But the macro cannot be executed like this...
It seems like the toggleSelect part works.(The Dummy-Serial is selected automaticaly too)
But if i want to clear by pushing the Clear-Button, the "Edit Module" Screen appears...
So i think the bold part does not work(I switch the "i" in first if-condition to "0",because "i" is initialized later. I think a little literal error,or?)
Sub SelectDummy
set val = ActiveDocument.Fields("SERIAL_NO").GetSelectedValues
if val.Count = 1 and val.Item(0).Text = "Dummy" then
ActiveDocument.Fields("SERIAL_NO").Clear
else
for i=0 to val.Count - 1
if val.Item(i).Text = "Dummy" then
check = true
exit for
end if
next
if check <> true then ActiveDocument.Fields("SERIAL_NO").ToggleSelect("Dummy")
end if
end sub
But i dont get the issue...
It needs another condition before the error-line:
if val.Count = 0 then exit sub
- Marcus
Yes now it works fine!
Thank u very much for help:)
Sarah