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 SkipVought 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 argument to a function

Status
Not open for further replies.

LRHatBSSS

IS-IT--Management
Dec 22, 2005
17
0
0
US
Hey folks!

In a form, a few fields should have their format (font color, type and weight) changed based on their value.

I created a function to be called once for each of the necessary fields, from within the OnCurrent trap event.

My problem is: how to pass the field name to the function (it will not necessarily be the current field, and not all fields on the form)

Below is a "short" version of the problem

Private Sub Form_Current()
On Error GoTo Err_Form_Current

fncRemarksButtons (Me.myField01)
fncRemarksButtons (Me.myField02)
fncRemarksButtons (Me.myField03)
...
fncRemarksButtons (Me.myFieldNN)


Exit_Form_Current:
Exit Sub

Err_Form_Current:
MsgBox Err.Description
Resume Exit_Form_Current

End Sub

_______________________________

Function fncRemarksButtons(varRemarksButton As Variant)

With varRemarksButton
If .Value = -1 Then
.Caption = "YES"
.FontWeight = conHeavy
.ForeColor = conDarkBlue
Else
.Caption = "NO"
.FontWeight = conNormal
.ForeColor = conBlack
End If
End With

End Function


Any help is truly appreciated.


L.R. Humberto

If you don't know where you are going to, doesn't matter how fast you are going, you'll never get there.
 
Hi!

Check out Conditional Formatting which you can access from the Format menu. You can change all sorts of formats based on the value of the control.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
You may try something like this:
Private Sub Form_Current()
subRemarksButtons Me.Controls("myField01")
subRemarksButtons Me.Controls("myField02")
subRemarksButtons Me.Controls("myField03")
...
subRemarksButtons Me.Controls("myFieldNN")
End Sub
_______________________________
Sub subRemarksButtons(varRemarksButton As Control)
With varRemarksButton
If .Value = -1 Then
.Caption = "YES"
.FontWeight = conHeavy
.ForeColor = conDarkBlue
Else
.Caption = "NO"
.FontWeight = conNormal
.ForeColor = conBlack
End If
End With
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thx, Jeff, for your input but i'm looking for a function that will give me a bit more flexibility during runtime.

Thank you PH for your tip also. I tried it but i'm getting errors. If i leave the field name in quotes (as in your suggestion) the error message states "can't find the field...", and taking off the quotes naturally causes the valued of the field to be used causing another error (and it's not the value i want to passs anyway).

Any more ideas?

L.R. Humberto

If you don't know where you are going to, doesn't matter how fast you are going, you'll never get there.
 
LR, this should work???

Private Sub Form_Current()
subRemarksButtons (Me.myField01)
subRemarksButtons (Me.myField02)
subRemarksButtons (Me.myField03)
...
subRemarksButtons (Me.myFieldNN)
End Sub
_______________________________
Sub subRemarksButtons(ctlRemarksButton As Control)
With ctlRemarksButton
If .Value = -1 Then
.Caption = "YES"
.FontWeight = conHeavy
.ForeColor = conDarkBlue
Else
.Caption = "NO"
.FontWeight = conNormal
.ForeColor = conBlack
End If
End With
End Sub


BUT you said, it won't always be the current Field???
...how can you reference it then?
You're using the "Caption" property of a control,
and also it's "value" ...isn't that a contradiction???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top