Changing Font Colour

G

Guest

Hi

Its always the simple things that throw you.

I am trying to loop though some controls on a form. Where the tag property
has "Pick" and the value of the control is greater than Zero
The data in the control is Currency I thought I could access the value of
the control by using the value property but not so... Help would be
appreciated

The code below does work until a I add the Code Asterisked. Problem is I
dont want all controls bold red only those with value greater than £Zero


Private Sub Form_Current()
Dim C As Control
For Each C In Me.Controls
If C.Tag = "tick" ***And C.Value > 0**** Then
With C
.ForeColor = vbRed
.FontBold = True
End With
End If
Next
End Sub

Thankyou
 
J

Jeff Boyce

Melba

What I noticed was that you don't have any way in your code to turn off the
red/bold (add an Else statement to do this).

If you add a breakpoint in your code on the "IF" statement line, you could
run this code and step through each cycle/control, inspecting the values the
code is using to see if that gives you a clue. Hint: if you position your
cursor over the .Tag and .Value text in the code, while in break mode, the
underlying value of these will pop up like a tooltip.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
G

Guest

...
Jeff

Hi

Thanks for the response. Note your comments vis a vis adding an ELSE
Statement. I had intend to do so but tried first part of the code because was
not sure that the code to change the font where TAG = Pick and Contents
greater than £0.00 would work

The VB editor does not seem to like the expression ...C.Value where C =
Control on the form

When Code is run it generates run time error 438 "object does not support
property or method"

If I expressed a control individually to wit

If me.ControlName > than 0 then
Psuedo Code
Font would be red or black or green or whatever that works okay

Is there a C dot Property I can place in the code to evaluate the contents
of a given control on the form where that value (in this case is formatted as
curreny)
and must be greater than £0.00

Thanks in advance


:
 
J

Jeff Boyce

Melba

When you have VBA cycle through the controls ("For Each C in Me.Controls"),
it looks at EVERY control, not just the ones you want it to.

If you want to limit it to looking at textboxes only, you need to use an
If...Then statement "inside" the For Each loop, and only do your formatting
on those that are appropriate.

I don't recall the exact syntax, but seem to remember something on the order
of:
If C.TypeOf = acTextBox Then...

Access HELP should have an example of the For Each loop in which it checks
the type of control...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
G

Guest

Jeff
Hi

Thank you I mistakenly thought if I limited it to those controls where the
tag was set to "Something" then it would limet the cycle to these controls.

Much appreciiate your patience
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top