Help With Macro

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
 
R

Roy

Ok Ive sorted out the cancel box run time error now i just need help
with the 2nd item the macro now is:


Dim szNewEntry As String
szNewEntry = InputBox("ADD NEW ITEM TO LIST")
If szNewEntry = "" Then
Exit Sub
Else
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
ActiveDocument.FormFields("Dropdown1").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown1").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown3").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown3").Result _
= szNewEntry
ActiveDocument.FormFields("Dropdown2").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.Protect wdAllowOnlyFormFields, _
NoReset:=True
ActiveDocument.FormFields("Dropdown2").Result _
= szNewEntry

'ActiveDocument.Save
End If
End Sub


Thanks to Doug Robins from another thread!!

Roy
 
R

Roy

Hey what do you know a bit more playing & i have it sorted,

Dim szNewEntry As String
szNewEntry = InputBox("ADD NEW ITEM TO LIST")
If szNewEntry = "" Then
Exit Sub
Else
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
ActiveDocument.FormFields("Dropdown1").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown2").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.FormFields("Dropdown3").DropDown.ListEntries.Add
szNewEntry
ActiveDocument.Protect wdAllowOnlyFormFields, _
NoReset:=True

'ActiveDocument.Save
End If
End Sub

Shorter Code & the right RESULT!!!!!


Sorry to bother you hope this thread helps someone else,

Cheers

Roy
 

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