Command Buttons again

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Trying to get a command button to concatenate values in two text boxes and
display it on to a label on the same form.

I have
Private Sub cmdDisplay_Click()
lblFullName.Caption = txtFirst.Text & txtLast.Text
End Sub

I get an error saying the control needs to have the focus, but I have
references to two controls (txtFirst and txtLast).

Is there a fix?
 
Trying to get a command button to concatenate values in two text boxes and
display it on to a label on the same form.

I have
Private Sub cmdDisplay_Click()
lblFullName.Caption = txtFirst.Text & txtLast.Text
End Sub

I get an error saying the control needs to have the focus, but I have
references to two controls (txtFirst and txtLast).

Is there a fix?

In Access, it's a control's Value property you need to use, not it's
text property.
Look them up in VBA help to learn the difference.

Because the Value property is the control's default, you do not need
to state it:

lblFullName.Caption = txtFirst & txtLast

Note: Don't you want a space between the 2 names?
lblFullName.Caption = txtFirst & " " & txtLast
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top