Document variable names are Strings, so it would be best practice to convert
the value of "recordNum" to a String using the CStr function first -
especially if you've declared it as an Integer or Long. However, Word is
fairly accommodating and will force the conversion to a String automatically;
it's just neater and (possibly) safer to do an explicit conversion.
BTW, if the value of "recordNum" is incremented sequentially somehow
(perhaps in an array?), you could save yourself a lot of coding by using a
loop structure. For example:
Private Sub SaveRecordNums()
Dim i As Integer
Dim myVariableName As String
For i = LBound(myArray) To UBound(myArray)
myVariableName = "RecordNum" & i
ActiveDocument.Variables.Add myVariableName, CStr(myArray(i))
Next i
End Sub
In this example, the code simply loops through an array (called "myArray")
starting with the first item in the array and ending with the last and
creates the document variables on the fly using a pseudo-constant "RecordNum"
and appending the value of the loop's counter to it. Just be aware that if
the document variable already exists, trying to create it again may throw an
error. In addition, note the use of the CStr function to convert the value
from the array to a String. This is because document variable values are also
stored as Strings, and the same caveat applies as with the name.
--
Cheers!
Gordon Bentley-Mix
Word MVP
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.