Click here to Skip to main content
15,888,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed a form in Word 2010 with several embedded macros running on Click events from Command Buttons.

The problem is that when the Click event is activated it clears data in form fields and unchecks all previously checked check boxes. How do I keep the command button click events from clearing my form fields and check boxes?

Thanks!

Here is the code from the shortest Click event:

Private Sub CommandButton3_Click()
'Adds lines to the specifications table

Dim Count1 As Integer

ActiveDocument.Unprotect

Dim InsertRows1 As Integer
InsertRows1 = InputBox("Question", _
"InsertRowsTitle", "How many specifications are applicable for this qualification?")

InsertRows1 = InsertRows1

ActiveDocument.Tables(3).Select
ActiveDocument.Tables(3).Rows(1).Select
Selection.Copy
While Count1 < InsertRows1
Selection.Paste
Count1 = Count1 + 1
Wend

ActiveDocument.Protect wdAllowOnlyFormFields

End Sub


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 28-Jun-11 8:13am
v3
Comments
S Houghtelin 28-Jun-11 7:56am    
Which click event? Some code would be helpful.
Richard MacCutchan 28-Jun-11 9:40am    
The obvious answer is: fix your code so it does not do this. Other than that it's impossible to guess what you are doing.

There are several problems here.

InsertRows1 is decalred as an integer inputboxes return strings. if text is entered then it will generate type mismatch error.

If it is a string you are looking for, use something like:
strReply = InputBox("Message or instructions", "Title Bar Text")
this will return the string typed into the textbox of the input box dialog.

Anything equal to itself will not change the value, not sure what you are trying to do here.
VB
InsertRows1 = InsertRows1


For manipulating tables in Word I can suggest reasding this article:
http://msdn.microsoft.com/en-us/library/aa537149(v=office.11).aspx[^]

However, given the errors, you may want to learn more about VBA in general.
http://visualbasic.about.com/od/learnvba/a/aa021503.htm[^]
[edit] Added VBA tutorial link for Word.
 
Share this answer
 
v2
private void ClearForm()
{
     foreach(Control c in this.Controls)
     {
          if(c is TextBox || c is ComboBox)
               c.Text = "";
          else if (c is CheckBox)
               ((CheckBox)c).Checked = false;
          else if (c is RadioButton)
               ((RadioButton)c).Checked = false;
     }
}


call that method OnClick in C#
 
Share this answer
 
Comments
fjdiewornncalwe 28-Jun-11 14:53pm    
Backwards... He wants to know the exact opposite of what you have answered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900