Trouble with Function Call

  • Thread starter Thread starter Eddy
  • Start date Start date
E

Eddy

I a trying to call the following function on the After Update event of a
control. The function code is:

Function ShadeCtls(txt As TextBox)
Dim ctlName As TextBox

Set ctlName = txt
If IsNull(ctlName) Or ctlName = 0 Then
ctlName.BackColor = 16777215
Else: ctlName.BackColor = 8454143
End If
End Function

I am having trouble in the event procedure for the control. I try to call
the Function using: ShadeCtls(Field1) Where Field1 is the field name and
I get an Object Required error. I have also tried putting the field name in
quotes which produced a type mismatch error.

How can I carry over the ctl name so it can be used in the Function?

Thanks once again.
 
Eddy said:
I a trying to call the following function on the After Update event of a
control. The function code is:

Function ShadeCtls(txt As TextBox)
Dim ctlName As TextBox

Set ctlName = txt
If IsNull(ctlName) Or ctlName = 0 Then
ctlName.BackColor = 16777215
Else: ctlName.BackColor = 8454143
End If
End Function

I am having trouble in the event procedure for the control. I try to call
the Function using: ShadeCtls(Field1) Where Field1 is the field name and
I get an Object Required error. I have also tried putting the field name in
quotes which produced a type mismatch error.


You seem to be confusing the control object and the name of
the control. Or maybe the confusion is between the control
that is displaying a field's value and the field in the
form's record source table/query.

Your function's code looks like it will work as long as the
argument you pass to it is a control object, not the name of
a control.

If Field1 in your function call is the name of a text box
**control**, your code should work. It will not work if you
pass a string containing the name of a control.

If Field1 is the name of a **field/column** in the form's
record source and not the name of a text box **control**,
then the procedure will be trying to operate on the wrong
object.

Anyway, the key to your question lies in the thing(?) you're
calling Field1.
 
Back
Top