单击事件清除表单-帮助! [英] Click Event Clears Forms - Help!

查看:120
本文介绍了单击事件清除表单-帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Word 2010中开发了一个窗体,该窗体具有在命令按钮的Click事件上运行的几个嵌入式宏.

问题在于,激活Click事件后,它将清除表单字段中的数据,并取消选中所有先前选中的复选框.如何防止命令按钮单击事件清除我的表单域和复选框?

谢谢!

这是最短的Click事件中的代码:

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]添加了代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

这里有几个问题.

将InsertRows1缩放为整数输入框,返回字符串.如果输入文本,则将生成类型不匹配错误.

如果您要查找的是字符串,请使用类似以下内容的内容:
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.

InsertRows1 = InsertRows1



对于在Word中操作表格,我建议您重新设置这篇文章:
http://msdn.microsoft.com/en-us/library/aa537149 (v = office.11​​).aspx [ http://visualbasic.about.com/od/learnvba/a/aa021503.htm [ ^ ]
[edit]为Word添加了VBA教程链接.



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.


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;
     }
}



在C#中调用该方法OnClick



call that method OnClick in C#


这篇关于单击事件清除表单-帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆