Macro not working

C

chris

Can anyone help with the message: "Run-time error 5941: The requested member
of the collection does not exist."
The macro is as follows:

Sub fNameExit()

Dim Name As Variant
Dim Address1 As Variant
Dim Address2 As Variant
Dim Phone As Variant
Dim Fax As Variant
Dim Indx As Long

Name = Array("Bundaberg Assessing Centre", "Cairs Assessing Centre", "Eight
Mile Plains", "Mackay Assessing Centre", "Maroochydore Assessing Centre",
"Rockhampton Assessing Centre", "Southport Assessing Centre", "Toowoomba
Assessing Centre", "Townsville Assessing Centre", "Zillmere Assessing Centre")
Address1 = Array("addresses included here")
Address2 = Array("Bundaberg QLD 4670", "Earlville QLD 4870", "Eight Mile
Plains QLD 4740", "Mackay QLD 4740", "Maroochydore QLD 4558", "North
Rockhampton QLD 4700", "Southport QLD 4215", "Toowoomba QLD 4215",
"Aitkenvale QLD 4814", "Zillmere QLD 4034")
Phone = Array("phone numbers inserted here")

Indx = ActiveDocument.FormFields("fName").DropDown.Value

Indx = Indx - 1

ActiveDocument.FormFields("fAddress1").Result = Address1(Indx)
ActiveDocument.FormFields("fAddress2").Result = Address2(Indx)
ActiveDocument.FormFields("fPhone").Result = Phone(Indx)
ActiveDocument.FormFields("fFax").Result = Fax(Indx)

End Sub
 
J

Jezebel

It means that one of your formfield references is incorrect - most likely a
typo either in your code or when you named the formfield in the first place.
The debugger should be highlighting the faulty line.
 
C

chris

Thanks Jezebel. Evidently I'm a complete novice and am just learning the
true power of Word. It is highlighting the line:

Indx = ActiveDocument.FormFields("fName").DropDown.Value

I have titled the dropdown bookmark name as 'Name'. Is there somewhere else
I need to rename the form field?

Chris
 
J

Jay Freedman

The field name you supply within quotes in the code must match the
bookmark name in the Properties dialog of the field. Either change the
code to say FormFields("Name") or change the bookmark to fName.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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

Top