Using WITH statement and variables

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

Guest

Hi,

I want to create a function to change the fore colour of a specified control
on a specified form, but get an error when trying to use a variable with the
WITH statement:

Form mousemove event calls the function.

Private Sub Text1_MouseMove()
Call Change_Control_Colour("Forms!Form1","Text1")
End Sub

Public Function Change_Control_Colour(strForm, strControl AS String)

With strForm & "!" & strControl
.Forecolor = 255
End With

End Function

Can anyone help? (the code above is an example and may not work!)

Cheers,
Steve.
 
Hi:

Try this --
Private Sub Text1_MouseMove()
Call Change_Control_Colour(Text1)
End Sub

Public Function Change_Control_Colour(ctl as Access.Control)

With ctl
.Forecolor = 255
End With
End Function

Regards,

Naresh Nichani
Microsoft Access MVP
 
I have tried it but it doesnt quite work.

When the function is called ctl is Null. There are no errors but the colour
does not change.

Cheers.
Steve.
 
Sorry!

I did work, I wanted the Forecolor of the associated label to show a
different colour, not the textbox itself!

D'Oh!

Thanks for the help (it saves a lot of 'background' coding to highlight the
labels)

Steve.
 
Back
Top