Formfields

G

Greg Maxey

Bert,

Something like this:

Sub Test()
MsgBox Selection.FormFields(1).Name
End Sub
 
B

Bert Nargs

Hi Greg,
Thanks for your response.
Unfortunmately this only gives me the name of the first formfield in the
document, i.e. Selection.FormFields(2).Name will give me the name of the
second formfield.

I would like to know which formfield I have selected so that I can execute a
single macro rather than have a separate macro for every single Formfield.

I have tried various combinations of selection but they all seem to rely on
me knowing which number I have selected. Surely VB knows?
Best wishs.
 
G

Greg Maxey

Bert,

I am not sure exactly what you are trying to do. In addition to Doug's
suggestion, here is a bit of code that will determine the index number of a
formfield on entry for use later on exit:

Sub GetIndexOnEntry()
'Gets the index value for use in the Exit event
Dim oDoc As Document
Set oDoc = ActiveDocument
oDoc.Variables("Index").Value = _
oDoc.Range(0, Selection.Bookmarks(1).Range.End).FormFields.Count
End Sub

Sub ReportNameOnExit()
Dim oDoc As Document
Dim i As Long
Set oDoc = ActiveDocument
i = CStr(oDoc.Variables("Index").Value)
MsgBox oDoc.FormFields(i).Name
End Sub
 
B

Bert Nargs

Thankyou guys.
I think I was confusing selection.FormFields(1) with
ActiveDocument.FormFields("Check1") o r vice versa.
I needed the name in order remotely to change the status of another
FormField i.e Staus of Check1 changes Check11, Check2 changes Check12.....
BWs
 
G

Greg Maxey

Bert,

Again, you could run an on entry macro to determing the index number of the
field you just entered and then use that value in the on exit event.
However, I still don't see how you are going to be able to use the "same"
macro in all of your fields (in one instance you want to set the value of
check11 and in another you want to check the value of check 12) unless there
is exactly 10 fields between each pair (i.e., check1 always sets check11,
check 2 always sets check12 ... check100 always sets check110, etc.) in that
case, I suppose that you could use something like:

Sub RunOnEntry()
ActiveDocument.Variables("Index").Value = _
ActiveDocument.Range(0,
Selection.Bookmarks(1).Range.End).FormFields.Count
End Sub
Sub RunOnExit()
Dim oFrmFld As FormFields
Dim i As Long
i = CStr(ActiveDocument.Variables("Index").Value)
Set oFrmFld = ActiveDocument.FormFields
If oFrmFld(i).CheckBox.Value = True Then
i = i + 10
oFrmFld(i).CheckBox.Value = True
Else
i = i + 10
oFrmFld(i).CheckBox.Value = False
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top