打字时更新文本框

问题描述:

在Access中,我有其中有三个文本框的形式。 我想更新一个名为文本框的 tbxCombinedName 的结合两者的组合:

In Access, I have a form in which there are three textboxes. I am trying to update a textbox called tbxCombinedName with a combination of both:

  • 在文本框的 tbxLastName 的(人的姓氏)
  • 在文本框的 tbxFirstName 的(人的名字)
  • textbox tbxLastName (person's Last Name)
  • textbox tbxFirstName (person's First Name)

我的问题是:我该用什么文本框属性,所以,当我在输入文字的 tbxLastName 的,该CombinedName文本框更新的立即,然后保存在表联系人的。

My question is: what textbox property do I use, so that as I am typing text in tbxLastName, the CombinedName textbox is updated immediately and thereafter saved in the table Contacts.

微软的网站,我发现,在文本框中键入时的步骤流程如下:

On Microsoft's website, I have found that the step processes when typing in a textbox are as follows:

的KeyDown→键preSS→BeforeInsert→变化→的KeyUp

我已经使用的OnChange和的onkeydown性能试过,但无济于事。哪个属性,再加上什么code,将允许更新,为你型行动工作?

I've tried using the OnChange and OnKeyDown properties, but to no avail. Which property, combined with what code, will allow the update-as-you-type action to work?

这是我之前写的,没有工作:

This is what I wrote earlier, which didn't work:

Private Sub tbxLName_change()

Dim lastName As String
Dim nameCode As String

lastName = tbxLName.Value
Debug.Print lastName
nameCode = tbxNameCode.Value
nameCode = lastName
Debug.Print nameCode

End Sub

感谢提前你的所有帮助。

Thanks for all your help in advance.

这是少数情况下,你应该参考的.text属性之一。

This is one of the few cases where you should refer to the .text property.

在Change事件:

lastName = tbxLName.Text

为.text属性仅当一个控件具有焦点,它是指控制的可见内容。

The .text property is only available when a control has focus and it refers to the visible contents of the control.

不过,这是一个数据库和一般的规则是,你没有不存储计算字段。全名可以很容易地从查询得到的

However, this is a database and the general rule is that you no not store calculated fields. The full name can easily be obtained from a query.