Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update textbox during typing

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:

  • textbox tbxLastName (person's Last Name)
  • textbox tbxFirstName (person's First Name)

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 → KeyPress → BeforeInsert → Change → KeyUp

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.

like image 413
Paolo Bernasconi Avatar asked Aug 16 '12 11:08

Paolo Bernasconi


1 Answers

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

In the Change event:

lastName = tbxLName.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.

like image 93
Fionnuala Avatar answered Oct 20 '22 12:10

Fionnuala