Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a field as a parameter to a procedure 1

Status
Not open for further replies.

RSfromCO

Programmer
May 3, 2002
149
US
I have a report that does some conditional formating of field information. Basically if something doesn't appear correct, I want it to be "highlighted" on the form. So for a bunch of fields, I do this type of check....

If (MyField > 100) Then
Me!MyField.ForeColor = vbRed
Me!MyField.FontBold = True
Me!MyField.BorderStyle = 1
Else
Me!MyField.ForeColor = vbBlack
Me!MyField.FontBold = False
Me!MyField.BorderStyle = 0
End If
End If

This works fine, but I have many fields that I want to do the same thing with.

I want to write a procedure setHighlight, where I can pass the field control, and a TRUE/FALSE parameter. Within the setHighlight procedure the display properties of the control would be set based upon the TRUE/FALSE parameter.

I am not sure what to define the parameter as for the procedure declaration...

Public Sub setHighlight(ByRef field As ????????, ByVal highlight As Boolean)

And then I am not sure on the syntax to send the field to the procedure...
Call setHighlight(Me!MyField, TRUE) ???

I tried defining the parameter to the setHighlight procedure as an AccessObject. When I try to call the procedure however it looks like it tries to send the current value of the field to the procedure rather than sending the field object itself.

Any suggestions ???

 
Hi!

"Things" on forms or reports are controls, "things" in tables are fields. That said, you'd need to declare the control, as a control:

[tt]Public Sub setHighlight(ByRef ctl As Control, ByVal highlight As Boolean)[/tt]

Then call it like you do (peraps send the value to be tested against too, to make it a bit more dynamic?).

- if you're using access 2000+, take a look at conditional formatting, which would achieve the same without coding (well, except the border style).

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top