Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Guys,
How do I use Vb script to check if a Field contains a specific value?
The statement below is not working..
x = ActiveDocument.Fields("HolidayDate").SearchFor("05/10/2010",true,1)
Thanks?
Aldo,
Probably not the best way, but it works. You can start from here and agjust for your needs:
sub test
set f = ActiveDocument.Fields("HolidayDate").GetPossibleValues
c = f.Count
ctr=0
for i=0 to c-1
if f.item(i).text="05/10/2010" then
ctr=ctr+1
end if
next
' if ctr >0, the value exists
msgbox(ctr)
end sub
Hi,
SearchFor returns an array of elements which contain the string you provided. Check the lenght of the returned String or array. If it is 0 then it means your date is not found. I don't have much experience in Macro's this is jus a suggestion. Also please check whether the date format you provided is correct ?
Regards,
Syed.
Hi there,
Even searching for "05" or "*05*" is returning {...} and I Know I have the value 05/10/2010 in my listbox..
Is there any other way to check if the value 05/10/2010 is in the list box?
Aldo,
Probably not the best way, but it works. You can start from here and agjust for your needs:
sub test
set f = ActiveDocument.Fields("HolidayDate").GetPossibleValues
c = f.Count
ctr=0
for i=0 to c-1
if f.item(i).text="05/10/2010" then
ctr=ctr+1
end if
next
' if ctr >0, the value exists
msgbox(ctr)
end sub
Thanks man.
I find it easiest to use QV expressions with ActiveDocument.Evaluate. Then you just have to write the same QV expression you would use in a text box. Makes it easy to test.
Searching all values:
=FieldIndex('HolidayDate', '05/10/2010')
Searching possible values:
=sum(if(Date='05/05/2010',1,0))
Any of those expressions can be used in vb using the Evaluate() function.
x = ActiveDocument.Evaluate(" sum(if(Date='05/05/2010',1,0)) ")
-Rob
Thanks.
I knew there was a simpler way... ![]()