R
Roy
Hi
I am a real beginner to macros but have created some froms in word and
have adapted a macro from this site provided by Cindy Meister to update
a single form field, I have managed to get this to work several drop
down from fields with an added item OK though my code may be a bit
long!!!????
I have 2 problems though:
1: When the user input box opens "ADD NEW ITEM TO LIST" if you press
cancel it produces a run time error? and asks to debug. I dont know how
to do this i want the macro to end if cancel is selected what do i need
to do????
2: When the fields reset after the macro has run the new item is shown
in all the dropdown fields as the new item entered reseting any
previous entries in other dropdown form fields, can the Macro be edited
so that the new item appears in all the dropdown field lists but is not
shown unless selected in a specific field???
This is the code i am using
Dim szNewEntry As String
szNewEntry = InputBox("ADD NEW ITEM TO LIST")
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
ActiveDocument.FormFields("Dropdown1").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown1").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown2").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown2").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown3").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.Protect wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.FormFields("Dropdown3").Result _
= szNewEntry
'ActiveDocument.Save
End Sub
Any help you can provide would be greatly appreciated this is "my first
form" using macros so i am really not certain what i am doing, I must
say though that when you change something without help & it works it
feels great, but I really am out of my depth with this at the moment,
Thanks if you can show me what to do and where i am going wrong
Roy
I am a real beginner to macros but have created some froms in word and
have adapted a macro from this site provided by Cindy Meister to update
a single form field, I have managed to get this to work several drop
down from fields with an added item OK though my code may be a bit
long!!!????
I have 2 problems though:
1: When the user input box opens "ADD NEW ITEM TO LIST" if you press
cancel it produces a run time error? and asks to debug. I dont know how
to do this i want the macro to end if cancel is selected what do i need
to do????
2: When the fields reset after the macro has run the new item is shown
in all the dropdown fields as the new item entered reseting any
previous entries in other dropdown form fields, can the Macro be edited
so that the new item appears in all the dropdown field lists but is not
shown unless selected in a specific field???
This is the code i am using
Dim szNewEntry As String
szNewEntry = InputBox("ADD NEW ITEM TO LIST")
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
ActiveDocument.FormFields("Dropdown1").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown1").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown2").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown2").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown3").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.Protect wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.FormFields("Dropdown3").Result _
= szNewEntry
'ActiveDocument.Save
End Sub
Any help you can provide would be greatly appreciated this is "my first
form" using macros so i am really not certain what i am doing, I must
say though that when you change something without help & it works it
feels great, but I really am out of my depth with this at the moment,
Thanks if you can show me what to do and where i am going wrong
Roy