>Does anyone know how to translate the following MS Word macro to VFP code? My goal is insert "AK" if the contents of field "state" is blank.
> ActiveDocument.MailMerge.Fields.AddIf Range:=Selection.Range, MergeField:= _
> "State", Comparison:=wdMergeIfIsBlank, CompareTo:="", TrueAutoText:= _
> "MailMergeInsertIf1", TrueText:="", FalseAutoText:="MailMergeInsertIf2", _
> FalseText:=""
>Thanks in advance for your help.
Hi Mike,
That's "named argument" style and could be used in VB. Fox needs "positional arguments". That's each parameter should be in an exact position (optional ones could simply be omitted with a placeholder comma). You get the positions from command's help as :
expression.AddIf(Range, MergeField, Comparison, CompareTo, TrueAutoText, TrueText, FalseAutoText, FalseText)
So your macro translates to (assuming oWord = createobject("word.application") was used to create word object):
with oWord
.ActiveDocument.MailMerge.Fields.AddIf( ;
.Application.Selection.Range, ;
"State", ;
wdMergeIfIsBlank, ;
, ;
, ;
"AK")
endwith
I added "Application" to "selection" as a safe belt (with..endwith block might be in a lower level and "selection" applies to "application").
Cetin