R
Robert5833
Hi All;
I’m using Access 2007, Vista Business, 1 Gb ram
I hope there is a simple solution to my issue. I have a form with 20+ text
and combo boxes. I want their fore and back colors to change based on their
value. As it is now, I'm using a Case Select statement for each of them in
the form's Current event. But that seems too busy for what must be a global
procedure solution.
Code now (for one combo box control, others same):
Select Case Me.cboMonthLimitID
Case Is <= 0
Me.cboMonthLimitID.ForeColor = lngWhite
Me.cboMonthLimitID.BackColor = lngWhite
Case Is >= 1
Me.cboMonthLimitID.ForeColor = lngBlack
Me.cboMonthLimitID.BackColor = lngYellow
Case Else
Me.cboMonthLimitID.ForeColor = lngWhite
Me.cboMonthLimitID.BackColor = lngWhite
End Select
The above code works okay, although I have struggled with some fields
remaining highlighted after update (when I want them to revert to white
fore/back color when not = to a stated value).
I would prefer to use a global function or sub that would allow me to call
it from each named control in the form's Current event procedure. But I don't
know how or what to declare (Dim) in the global procedure or the calling form.
I have built and used other global or public functions and subs, but only
ones that included the named controls within.
Can a global procedure be called for a named control, without having to
declare each named control in the global procedure? (i.e., I would like to
have something that lets me call the global procedure to without having to
declare each control by name so I can use the routine for all of my forms and
reports.)
Also, what is the syntax used to call the global procedure at the control in
the form’s Current event procedure? (i.e., DoCmd.RunCommand.Me![control name]
gGetColor (as the global procedure name.)
I did find in another post this snippet from Marshall B., but I’m not clear
on how to modify it to my case:
“If the function is in a standard module, then use:â€
=yourfunction(Form)
“And code the function this way:â€
Public Function yourfunction(frm As Form)
If somecondition Then
frm.Section(0).BackColor = vbRed
Else …
I’m confused on the If / Then argument. I know what the condition will be
for all text and combo boxes on my form; either <=0 or >=1, etc., but it
seems for the If Then argument above I would have to declare the text or
combo box within that argument.
Can I Dim a reference for the global procedure such as Dim CTRL As Control,
and include that reference in the If Then argument?
I’m also unsure of the frm.Section(0) statements in the above snippet. I get
the part about frm as a variable or object identified in the procedures
declaration (yourfunction(frm As Form), but how do I tie it to the actual
object (my form) ?
Also, in this case I’m not sure what is being referenced in “Section(0).†Is
that a section on a form?
Simply stated what I need is a procedure that takes a constant value or
condition (condition A; <=0, or condition B; >=1), and returns either vbaRed
or vbaWhite accordingly. Then for each text or combo box on any of my forms I
want to call that procedure to set the fore and back color to red or white
based on that control’s condition.
Could someone please help me out of my ignorance on this? There are half a
dozen other instances where I feel a global procedure will simplify my code,
but I'm struggling with the constructs at the most basic level; when and
where to Dim/declare variables, and where and how to call the procedure for a
control at the form level.
I hope these questions make sense…I don’t even know enough to know what I
don’t know…and that’s never a good thing.
Best regards and thank you in advance for your help and patience.
RL
I’m using Access 2007, Vista Business, 1 Gb ram
I hope there is a simple solution to my issue. I have a form with 20+ text
and combo boxes. I want their fore and back colors to change based on their
value. As it is now, I'm using a Case Select statement for each of them in
the form's Current event. But that seems too busy for what must be a global
procedure solution.
Code now (for one combo box control, others same):
Select Case Me.cboMonthLimitID
Case Is <= 0
Me.cboMonthLimitID.ForeColor = lngWhite
Me.cboMonthLimitID.BackColor = lngWhite
Case Is >= 1
Me.cboMonthLimitID.ForeColor = lngBlack
Me.cboMonthLimitID.BackColor = lngYellow
Case Else
Me.cboMonthLimitID.ForeColor = lngWhite
Me.cboMonthLimitID.BackColor = lngWhite
End Select
The above code works okay, although I have struggled with some fields
remaining highlighted after update (when I want them to revert to white
fore/back color when not = to a stated value).
I would prefer to use a global function or sub that would allow me to call
it from each named control in the form's Current event procedure. But I don't
know how or what to declare (Dim) in the global procedure or the calling form.
I have built and used other global or public functions and subs, but only
ones that included the named controls within.
Can a global procedure be called for a named control, without having to
declare each named control in the global procedure? (i.e., I would like to
have something that lets me call the global procedure to without having to
declare each control by name so I can use the routine for all of my forms and
reports.)
Also, what is the syntax used to call the global procedure at the control in
the form’s Current event procedure? (i.e., DoCmd.RunCommand.Me![control name]
gGetColor (as the global procedure name.)
I did find in another post this snippet from Marshall B., but I’m not clear
on how to modify it to my case:
“If the function is in a standard module, then use:â€
=yourfunction(Form)
“And code the function this way:â€
Public Function yourfunction(frm As Form)
If somecondition Then
frm.Section(0).BackColor = vbRed
Else …
I’m confused on the If / Then argument. I know what the condition will be
for all text and combo boxes on my form; either <=0 or >=1, etc., but it
seems for the If Then argument above I would have to declare the text or
combo box within that argument.
Can I Dim a reference for the global procedure such as Dim CTRL As Control,
and include that reference in the If Then argument?
I’m also unsure of the frm.Section(0) statements in the above snippet. I get
the part about frm as a variable or object identified in the procedures
declaration (yourfunction(frm As Form), but how do I tie it to the actual
object (my form) ?
Also, in this case I’m not sure what is being referenced in “Section(0).†Is
that a section on a form?
Simply stated what I need is a procedure that takes a constant value or
condition (condition A; <=0, or condition B; >=1), and returns either vbaRed
or vbaWhite accordingly. Then for each text or combo box on any of my forms I
want to call that procedure to set the fore and back color to red or white
based on that control’s condition.
Could someone please help me out of my ignorance on this? There are half a
dozen other instances where I feel a global procedure will simplify my code,
but I'm struggling with the constructs at the most basic level; when and
where to Dim/declare variables, and where and how to call the procedure for a
control at the form level.
I hope these questions make sense…I don’t even know enough to know what I
don’t know…and that’s never a good thing.
Best regards and thank you in advance for your help and patience.
RL