PDA

View Full Version : Help with VBA code



lbartowski
06-17-2010, 11:57 AM
Here's what I've created so far in a userform:

Private Sub CommandButton1_Click()

Dim vName, vYear, vOut

vName = txtName
vYear = txtYear
vOut = lblOut

End Sub

I need to come up with a code that produces an output like this "vname is ? years old" with an ok button to end it. It's a little over my head.

Bob Phillips
06-17-2010, 12:14 PM
Private Sub CommandButton1_Click()

Dim vName, vYear, vOut

vName = txtName
vYear = txtYear
vOut = lblOut

MsgBox vName & " is " & vYear & " years old"

End Sub

lbartowski
06-17-2010, 12:48 PM
I need it written as part of a lable output. Here's what I have but I'm getting an error.

Private Sub CommandButton1_Click()
Dim vName, vYear, vOut

vName = txtName.Text
vYear = txtYear.Text

lblOut.Caption = "vName" & " is " & "Val(2010 - vYear)" & " years old"

JKwan
06-17-2010, 12:59 PM
Is this what you mean?

lblOut.Caption = vName & " is " & Val(2010 - vYear) & " years old"