Conditionally blacking out fields on a report (1 Viewer)

lipin

Registered User.
Local time
Today, 08:07
Joined
May 21, 2002
Messages
149
I have the following code in a report. I thought it would blackout the two fields in the detail section for the sections where the Job Code is 200. But it is blacking them out for all Job Codes. ( 100, 120, 200, 300, 600, 1500)

Am I putting it in the wrong place?




Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.JobCd = 200 Then
Me.TotalUnits.BackColor = 0
Me.UnitsPerHour.BackColor = 0
End If

End Sub
 

ChrisO

Registered User.
Local time
Today, 17:07
Joined
Apr 30, 2003
Messages
3,202
G’day lipin

I don’t like trying to answer questions about reports because they are somewhat of a visual thing to me.

However, it would seem that if Me.JobCd is ever equal to 200 then they would be blacked out and never set back again.
In other words the If statement needs an Else section to reset the BackColor back to normal.

Hope that makes some sense.

Regards,
Chris.
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
yes and no,

you have multiple job codes in the detail, and the code turns the entire detail for the entire section to whatever when its sees the job codes.

so you have to put nothing in the detail section, Visible = False and move the
detail section to the first group footer section, and make sure that the section is grouping on Job code. . . then move that code to the group footer

otherwise, there is no way to do individual row formatting in a detail section.

sportsguy
 
R

Rich

Guest
sportsguy said:
otherwise, there is no way to do individual row formatting in a detail section.

sportsguy

That's not true, Reports can format individual lines unlike Continuous forms where it's much more difficult
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
i will learn when a master appears

so Rich, enlighten me,
and otherwise help the original questioner. . .

otherwise, what was the point of that last post?

I have tried, and been unsuccessful,

tell me how to format myTextBox Red font when myImportantTextBox > "1102375"

thanks,

sportsguy
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:07
Joined
Feb 19, 2002
Messages
43,466
Since the background color remains from one record to the next, you need to handle the else condition also.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.JobCd = 200 Then
    Me.TotalUnits.BackColor = 0
    Me.UnitsPerHour.BackColor = 0
Else
    Me.TotalUnits.BackColor = ??
    Me.UnitsPerHour.BackColor = ??
End If

End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:07
Joined
Feb 19, 2002
Messages
43,466
tell me how to format myTextBox Red font when myImportantTextBox > "1102375"
In the format event:

Code:
If Me.myImportantTextBox > "1102375" Then
    Me.myImportantTextBox.ForeColor = vbRed
Else
    Me.myImportantTextBox.ForeColor = vbBlack
End If
 

ChrisO

Registered User.
Local time
Today, 17:07
Joined
Apr 30, 2003
Messages
3,202
I find it somewhat obnoxious to quote myself but anyway: -

In other words the If statement needs an Else section to reset the BackColor back to normal.

When we get down to the tintacks of the situation we may find toggling the foreground/background colour not the best solution.

Consider; a control may be blacked out, no problem, but if we reset it just what do we reset it to? Black foreground on white background?

What would happen if the report was printed on colored paper, or on parchment or over an image or any other situation I couldn’t even think of?

The aim therefore would seem to be to control the background property between transparent and normal, not directly with the colours for the ‘normal’ condition.
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
Thanks Pat,

I got it to work!
one never nose what a hack will learn when being chastised!

sportsguy
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:07
Joined
Feb 19, 2002
Messages
43,466
Sorry Chris, I didn't mean to steal your thunder but the posters had clearly not picked up on your suggestion so I elaborated.
 

ChrisO

Registered User.
Local time
Today, 17:07
Joined
Apr 30, 2003
Messages
3,202
No problem Pat because, as you would know, we do this for the members and not the thunder. The difference between thunder and stupidity generally relies on our ability to read and, indeed, the last post in a thread.

BTW, I enjoy it being pointed out to me when I’m being stupid, especially when the point is correct. But when the point is reversed I hope I can do the same for others.

I care not for whom it is, the only thing I ask is; Is it correct?

I maybe being selfish but that is the way I learn.

Regards,
Chris.
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
So why does the Italic not turn off??

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.MPA = 0 Then
    Me.MPA.ForeColor = vbBlack
    Me.MPA.FontWeight = vbNormal
    Me.MPA.FontItalic = vbNo
ElseIf Me.MPA < Me.MA Then
    Me.MPA.ForeColor = vbRed
    Me.MPA.FontWeight = vbBold
    Me.MPA.FontItalic = vbYes
ElseIf Me.MPA < Me.TA Then
    Me.MPA.ForeColor = vbBlue
    Me.MPA.FontWeight = vbNormal
    Me.MPA.FontItalic = vbNo
Else
    Me.MPA.ForeColor = vbBlack
    Me.MPA.FontWeight = vbNormal
    Me.MPA.FontItalic = vbNo
End If


End Sub


sportsguy
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.MPA > Me.TA Then
    Me.MPA.ForeColor = vbBlack
    Me.MPA.FontWeight = Normal
    Me.MPA.FontItalic = No
ElseIf Me.MPA > Me.MA Then
    Me.MPA.ForeColor = vbBlue
    Me.MPA.FontWeight = Normal
    Me.MPA.FontItalic = No
ElseIf Me.MPA = 0 Then
    Me.MPA.ForeColor = vbBlack
    Me.MPA.FontWeight = Normal
    Me.MPA.FontItalic = No
Else
    Me.MPA.ForeColor = vbRed
    Me.MPA.FontWeight = 5
    Me.MPA.FontItalic = True
End If


End Sub

Got it to work, except can't change the Font Weight,
i have tried vbBOLD, BOLD, 5, "Bold"

and the enumeration is no included,

of course

Doze 2000

sportsguy
 

sportsguy

Finance wiz, Access hack
Local time
Today, 03:07
Joined
Dec 28, 2004
Messages
363
of course,

its different in code,

FontWeight is in units of 100, from 0 to
up to 900
 

Users who are viewing this thread

Top Bottom