Calling a Sub passing Textbox name

D

Ducttape19

Hello all, I am new to this forum and still somewhat green in VBA but
have quite a bit of Delphi and C++ programming experience so that i
what makes my problem even more frustrating.

I have created a sub that will make changes to a textbox's propertie
based on the value the user entered compared to the value of a label.
I would like to be able to pass to this sub the names of the textbo
and the label that it should use for it's testing and changes.

Here is what I have written so far, keep in mind this doesn't work:

Sub TextBoxChanges(thebox As TextBox, thelbl As Label)
thebox.BackColor = RGB(255, 255, 255)
thebox.ForeColor = RGB(0, 0, 0)
If Val(thebox.Text) = Val(thelbl.Caption) Then
thebox.BackColor = RGB(0, 100, 0)
thebox.ForeColor = RGB(255, 255, 255)
ElseIf Val(thebox.Text) = Val(thelbl.Caption) - 1 Then
thebox.BackColor = RGB(255, 0, 50)
thebox.ForeColor = RGB(255, 255, 255)
ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) - 2 Then
thebox.BackColor = RGB(255, 255, 0)
thebox.ForeColor = RGB(0, 0, 0)
ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) + 1 Then
thebox.BackColor = RGB(165, 165, 165)
thebox.ForeColor = RGB(0, 0, 0)
End If

End Sub

Private Sub txt_h1_Change()
Call TextBoxChanges(txt_h1, lbl_p1)
End Sub

I have 18 text boxes so I would like to have an onChange event for eac
textbox so that I can save some code. Any help would be apreciated
please post back if you need more information. Thanks
 
B

Bob Phillips

Declare the arguments as control types

Sub TextBoxChanges(thebox As MsForms.TextBox, thelbl As MSForms.Label)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

Ducttape19

Thanks a bunch, that worked perfect. I knew that it wouldn't be muc
but when you don't know it can be frustrating. Anyways thanks
 

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

Top