Why isn’t this macro working?

B

blwrs

I recently inserted this macro in my word document (visual basic).

Sub OnExitDropDown1()
Dim oFFs As FormFields
Set oFFs = ActiveDocument.FormFields
Select Case oFFs("DropDown1").Result
Case "Person1"
oFFs("Text1").Result = "1376"
Case "Person2"
oFFs("Text1").Result = "4847"
Case "Person3"
oFFs("Text1").Result = "4805"
End Select
End Sub

Dropdown1 is my dropdown list of names and I would like their phone numbers
to automatically appear in a field “Text1â€. I have the macro running on exit
of the dropdown menu. The problem I’m having is that the field “Text1†isn’t
automatically updating when I select the name in the dropdown menu. It will
work but I have to go to tools/macro and hit run every time I want it to
update.
 
J

Jay Freedman

I recently inserted this macro in my word document (visual basic).

Sub OnExitDropDown1()
Dim oFFs As FormFields
Set oFFs = ActiveDocument.FormFields
Select Case oFFs("DropDown1").Result
Case "Person1"
oFFs("Text1").Result = "1376"
Case "Person2"
oFFs("Text1").Result = "4847"
Case "Person3"
oFFs("Text1").Result = "4805"
End Select
End Sub

Dropdown1 is my dropdown list of names and I would like their phone numbers
to automatically appear in a field “Text1”. I have the macro running on exit
of the dropdown menu. The problem I’m having is that the field “Text1” isn’t
automatically updating when I select the name in the dropdown menu. It will
work but I have to go to tools/macro and hit run every time I want it to
update.

It works perfectly well here. A couple of things to check:

- Did you protect the document for forms (click the lock icon on the forms
toolbar)?

- In the actual form, do the quoted names in the Case statements exactly match
the entries in the dropdown's properties, including cap/lower case and spaces?
(Probably they do, else running the macro from the dialog wouldn't work either.)
 
B

blwrs

Yes, I did protect the document and double checked the spelling etc.... still
no luck. I'm running 03, is that an issue?
 
J

Jay Freedman

No, running Word 2003 is not an issue. When I said "it works here", I had tried
it on Word 2003 and it works.

What is the setting in Tools > Macro > Security? If it's set to High, reset it
to Medium.

If that doesn't work, try making a different macro -- something simple, such as
just a MsgBox command to let you know when the macro runs -- and assign that as
the dropdown's exit macro. Does that work?
 

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