Need help in formulating a function

J

Jack

Hi,
I have the following code in got focus of a text box.

If ChannelOutput(strGetplantname1) = "A" Then


If (txtContPlan1.Text) <> "" Or Not (IsNull(txtContPlan1.Text)) Then
txtContPlan1.Locked = True
txtContPlan1.BackColor = vbYellow
Else
txtContPlan1.Locked = False
End If
ElseIf ChannelOutput(strGetplantname1) = "B" Then
'Do nothing
Else
If (txtContPlan1.Text) <> "" Or Not (IsNull(txtContPlan1.Text)) Then
txtContPlan1.Locked = True
txtContPlan1.BackColor = vbYellow
Else
txtContPlan1.Locked = False
End If
End If

Now I have to use the same kind of formula but to thirty other text boxes in
the same form.

This can be done by cutting and pasting and renaming etc. However i was
wondering if this can
be turned into a function that can be called at each event of the got focus
of the text box concerned.

Also the Channel is calculated field. So how does it play out in a function
here.
I would appreciate any help for resolution of this issue. Thanks.
 
G

GB

Don't know if this is the "best" way, but you could encapsulate your
procedure/function to pass in the control that is to be updated/checked from
each of the other got focus controls.

So, your procedure that does the work could be something like:

Private Sub ColorUpdate(ControlField as Control)

then substitute ControlField (in your original code) at all locations where
you have txtContPlan1

From your GotFocus procedure you would use something like:

Private Sub txtContPlan1_GotFocus()
Call ColorUpdate(Me.Controls("txtContPlan1"))
End Sub


And of course realize, as a part of programming control, that a change to
the colorupdate procedure will affect all textboxes that reference that
procedure.
 

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

Similar Threads


Top