Link to home
Start Free TrialLog in
Avatar of RichNH
RichNH

asked on

Access form text control not updating

I have an access 2007 form.  When I fill in two text fields for first and last names I have another field called full name which is supposed to take the two and put them together, as the names are typed in.  But Access isn't doing that.  There seems to be some sort of delay.  Even when I exit out of first name by clicking in the last name field the full name field doesn't take the value of first name in it.  When I type the first letter in last name the full name field suddenly shows the entire first name.  Any ideas?

Rich User generated image
Private Sub txtFirstName_Change()
    On Error GoTo Trap_Error: Current_Activity = "": Current_Form = "frmServiceAgents": Current_Routine = "txtFirstName_Change"
    Me.txtFullName = Trim(Me.txtFirstName) & " " & Trim(Me.txtLastName)
    DoEvents
Exit_Procedure:
    Exit Sub
Trap_Error:
    MsgBox Current_Form & ":" & Current_Routine & ":" & Current_Activity & vbCrLf & Err.Number & "-" & Err.Description & " @ " & Err.Source
    Resume Exit_Procedure
End Sub

Private Sub txtFirstName_Exit(Cancel As Integer)
    Me.Repaint
End Sub

Private Sub txtLastName_Change()
    On Error GoTo Trap_Error: Current_Activity = "": Current_Form = "frmServiceAgents": Current_Routine = "txtLastName_Change"
    Me.txtFullName = Trim(Me.txtFirstName) & " " & Trim(Me.txtLastName)
    DoEvents
Exit_Procedure:
    Exit Sub
Trap_Error:
    MsgBox Current_Form & ":" & Current_Routine & ":" & Current_Activity & vbCrLf & Err.Number & "-" & Err.Description & " @ " & Err.Source
    Resume Exit_Procedure
End Sub

Private Sub txtLastName_Exit(Cancel As Integer)
    Me.Repaint
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
no points please.

Just to clarify MX's post.

The default property of the textbox control is the Value property.  So, when you refer to me.txtFirstName what you are actually saying is me.txtFirstName.Value

However, when you are typing in a control, the "Text" property is what you are changing, not the "Value" property.  And the only time you can actually refer to the controls "Text" property is when that control has the focus.  Until you have moved the focus to some other control, the "Text" and "Value" properties will not contain the same information.  Once you have moved the focus from that control, the "OldValue" property is set to the "Value" property, and "Value" property is set to equal the "Text" property.

When you are working in the Change event, you should always work with the "Text" property.
Avatar of RichNH
RichNH

ASKER

Outstanding!  Thank you both.
Thanks Dale ... I was just wait to be sure that fixed the issue before explaining ...

mx