473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Conditional formatting in a report

Alireza355
Dear all,

I have a report with some fields in it. I want the allignment of Field1 be Left-alligned if Field2 is >0 and Right-alligned if Field3 is >0

Note: It is not possible for both Field2 and Field3 to be >0 at the same time.

Is this possible????????????
May 2 '09 #1
21 5032
I also want to do the same in a subform.

Does anyone have any idea how?
May 2 '09 #2
ADezii
8,834 Expert 8TB
@Alireza355
Is this possible????????????
It is very possible, and it would be done in the Format() Event of the Report's Detail Section, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2. Const conALIGN_GENERAL = 0
  3. Const conALIGN_LEFT = 1
  4. Const conALIGN_RIGHT = 3
  5.  
  6. If Me![Field2] > 0 Then
  7.   Me![Field1].TextAlign = conALIGN_LEFT
  8. ElseIf Me![Field3] > 0 Then
  9.   Me![Field1].TextAlign = conALIGN_RIGHT
  10. Else        'a Catch-All, align General
  11.   Me![Field1].TextAlign = conALIGN_GENERAL
  12. End If
  13. End Sub
May 2 '09 #3
NeoPa
32,556 Expert Mod 16PB
Are you sure this works ADezii?

I would have thought this would change the format of the control a number of times before the page is formatted. Whichever was the last to run would determine the eventual display of the control for all records of that page.

Essentially the format of the control is associated with the control (of which there is only one instance).

My answer would be that it's not possible, unless you formatted the data of each record with a Format() function call. There are various drawbacks to this method (Controlling the format is not straightforward; The result becomes a string and no longer numeric; etc), but I see no other way working.
May 2 '09 #4
OldBirdman
675 512MB
If Field1 is a calculated value, then NeoPa's idea would work. It wouldn't matter if a numeric became a string. The font would be best if constant-width characters were used. So assuming a width for Field1 of 10 characters, then
Expand|Select|Wrap|Line Numbers
  1. Field1 = String(10 - Len(Format(Field2 + Field3, "#########0")), " ") & Location
May 2 '09 #5
ADezii
8,834 Expert 8TB
@NeoPa
Are you sure this works ADezii?
Actually, I'm 100% sure that it DOESN'T WORK! Oops, and sorry for the misinformation, guys. Nice pickup, NeoPa, and thanks.
May 2 '09 #6
I got it working this way in my report:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. If Field1 > 0 Then
  4. Text137.TextAlign = 3
  5. End If
  6.  
  7. If Field2> 0 Then
  8. Text137.TextAlign = 1
  9. End If
  10.  
  11. End Sub
But now I'm wondering how to do it in a subform........ Any idea? (:
May 3 '09 #7
NeoPa
32,556 Expert Mod 16PB
Ali.

Please review posts #4 & #6.

That cannot work correctly, even though it may seem to in some circumstances.
May 5 '09 #8
FishVal
2,653 Expert 2GB
@NeoPa
;)

Actually it does work corrrectly.

Regards,
Fish.
May 5 '09 #9
ADezii
8,834 Expert 8TB
@FishVal
Hello Fish, you mean that I was Right, then Wrong, then Right again, all in the same Thread? (LOL)
May 5 '09 #10
FishVal
2,653 Expert 2GB
@ADezii
Did you enjoy that?
Do you want a second go? LOL.
May 5 '09 #11
NeoPa
32,556 Expert Mod 16PB
@FishVal
Can you explain?
May 5 '09 #12
FishVal
2,653 Expert 2GB
@NeoPa
There is nothing to explain.
It works (at least in Access 2003). Try and see.
May 5 '09 #13
NeoPa
32,556 Expert Mod 16PB
Nothing to explain :S

Looking more closely, it does seem like using the Detail_Format() event procedure renders the stated problem irrelevant. As this event occurs for each detail record displayed, there is no possibility of incorrect carry-over (see post #4).

Well done for pointing out that it works anyway. You're obviously spot on there Fish.
May 5 '09 #14
What I wrote in post number 7 IS working PERFECTLY.

But now, I want to do the same in a subform, and can't ):
May 6 '09 #15
NeoPa
32,556 Expert Mod 16PB
@Alireza355
Yes. That's the conclusion we've all reached now Ali. I was mistaken earlier.
@Alireza355
You will need to help us here a little.

If that works in the main form, why is putting the same code in the form you use in your subform not working for you? It seems very straightforward. It makes it hard to know what the problem is. Perhaps if you explain what you've tried and what results you saw that indicate that it's not working we could help.
May 6 '09 #16
The code I gave to you earlier:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
  2.  
  3. If Field1 > 0 Then 
  4. Text137.TextAlign = 3 
  5. End If 
  6.  
  7. If Field2> 0 Then 
  8. Text137.TextAlign = 1 
  9. End If 
  10.  
  11. End Sub
I am using this code in the On Format event of the Detail section of a REPORT.

I haven't been able to do anything in a form or subform. What I want to do is to right-allign or left-align text in a textbox of a subform in datasheet view, based on another textbox of the same subform being >0.

The code I am using in the On Format event of the Detail section of my report is working perfectly, but I don't know where to put it in my subform or textboxes to make it work in my subform :(
May 7 '09 #17
NeoPa
32,556 Expert Mod 16PB
Ali,

I missed your changing from reports to forms. This is an entirely different question, and there is no way, other than using a limited set of conditional formats, to do this with forms (main or sub).

I was thinking mainly about forms when I posted what I did in post #4. This may not be correct for reports, but it certainly is for forms.

On another point, please make sure to use CODE tags in future whenever posting code. It is a requirement of using these forums. You've been using the forum for long enough to know and I've certainly had to edit a number of your posts.
May 7 '09 #18
mshmyob
904 Expert 512MB
What version of Access are you using? I can probably make it work in AC2007 but not earlier versions.

cheers,
May 7 '09 #19
I am using access 2003.

I have noticed that conditional formatting is limited to text color and background color, text bold and italic but NOT text allignment.
May 9 '09 #20
NeoPa
32,556 Expert Mod 16PB
@Alireza355
Very good point Ali. I'm sorry if I misled you :(

I'm afraid that I still see no viable alternative, other possibly, than returning a formatted string and trying to ensure this fits as expected into the control it's to be displayed in. A bit of a kludge, but the best I can think of certainly.
May 11 '09 #21
Thanks anyway.

I wish you the very best.

Best Regards,
Alireza355
Isfahan, Iran
May 12 '09 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Von Bailey | last post by:
I have a form where the conditional formatting is set on some fields to bold if certain conditions are met. However, when the conditions are met some of the data that is to bold is either not...
3
by: Chuck Reed | last post by:
I am working on a sales report where I show weekly sales by category for each of the 52 weeks in the year. Each record in my table/report has the 52 weeks of sales in it. I want to highlight to top...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
1
by: DavidB | last post by:
I have a report that (among other data) lists three different date fields from one of my tables. This is a validation report in that date #1 and date #2 should be earlier than date #3. The report...
2
by: enywu | last post by:
Hi all, I have created a report in my access database through a query. The report has no problem, however now there is new request that they want this report to use the conditional formatting....
4
by: riaane | last post by:
Please help: I have Conditional Formatting on a Report Field that fills the background Red if the criteria is met. This displays correctly in Report View, however, when I "OutputTo" this report to...
5
by: Desitech | last post by:
I have a Label on a report with a check box from a table indicating True or False. I would like to have the labels that are true to highlight yellow using conditional foramtting. The False labels to...
2
by: emckesso | last post by:
Hello, I need to create conditional formatting of a text box in the detail section of a report. The formatting is based on multiple parameters that are stored in a query. For example, pretend...
3
by: Rhys Gottwald | last post by:
Hi All, I have a report that is going to have 30 odd fields each containing a number, the number is the wind speed. I want to format the background of the field based on the value of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.