By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,096 Members | 1,348 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,096 IT Pros & Developers. It's quick & easy.

vb6 Data Report - Change text color at Runtime

P: 5
Hi, Please anyone out there can help me!!!!!!!!!!!!
I am building a Data Report in vb6. To make it simple there a three text box on the Report. First for (Date), Second for (In-Time) and the third for (Out-Time). The data is being filled in the text box from SQL Database.
What i want is to put condition that if (In-Time) is greater than e.g. 07:30 then the time diplayed in the text box must be RED in color in the report. Likewise if the (In-Time) is less than 07:30 the text color should be Black color.

Thanks a Zillion!!!!!!!!!!!!!!!!!!!!!!!
Mar 25 '07 #1
Share this Question
Share on Google+
14 Replies


Dököll
Expert 100+
P: 2,364
Greetings, Irfi!

I hear your pain. I tried something with a textbox and it did not work for me either. I am going to take another shot at it in a moment. Someone will likely come up with a better solution. No worries. In the meantime, Here is a solution. You should consider adding labels to gather the time from the database whereby:

Your form code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub SearchData_click()
  3.  
  4. ....your existing code goes here
  5.  
  6.     If Label1.Caption > 7:30 Then
  7.     Label_Value = "BLUE"                     
  8.     Label_BG.Change_It
  9.  
  10.     ElseIf Label1.Caption < 7:30 Then
  11.     Label_Value = "BLACK"                 
  12.     Label_BG.Change_It
  13.  
  14.     End If
  15.  
  16. End Sub
  17.  
  18.  
You may also need to make your label a diffrent colour since text usually comes in black


Now you need to build a module..

Module code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Label_Value As String
  3.  
  4. Public Sub Change_IT()
  5.  
  6.     If UCase(Label_Value ) = "BLUE" Then               
  7.     Form1.Label1.BackColor = &HFF0000
  8.     ElseIf UCase(Label_Value ) = "BLACK" Then        
  9.     Form1.Label1.BackColor = &000000
  10.  
  11.     End If
  12. End Sub
  13.  
  14.  
Form1 is the name of the form that has the Labels, by the way, I am sure you already know this.

Good luck. Let us know if this does not work. Again someone may see something I am not seing:-)

Dököll
Mar 25 '07 #2

SammyB
Expert 100+
P: 807
Hi, Please anyone out there can help me!!!!!!!!!!!!
I am building a Data Report in vb6. To make it simple there a three text box on the Report. First for (Date), Second for (In-Time) and the third for (Out-Time). The data is being filled in the text box from SQL Database.
What i want is to put condition that if (In-Time) is greater than e.g. 07:30 then the time diplayed in the text box must be RED in color in the report. Likewise if the (In-Time) is less than 07:30 the text color should be Black color.

Thanks a Zillion!!!!!!!!!!!!!!!!!!!!!!!
You just need to check the time and set the ForeColor property of the TextBox. Something like this, except you will probably already have the time in a DateTime variable.
Expand|Select|Wrap|Line Numbers
  1.     Dim dt As Date
  2.     Dim dtMin As Date
  3.     dtMin = CDate("7:30")
  4.     dt = CDate(TextBox1.Text)
  5.     If (dt < dtMin) Then
  6.         TextBox1.ForeColor = vbRed
  7.     Else
  8.         TextBox1.ForeColor = vbBlack
  9.     End If
Mar 25 '07 #3

P: 5
You just need to check the time and set the ForeColor property of the TextBox. Something like this, except you will probably already have the time in a DateTime variable.
Expand|Select|Wrap|Line Numbers
  1.     Dim dt As Date
  2.     Dim dtMin As Date
  3.     dtMin = CDate("7:30")
  4.     dt = CDate(TextBox1.Text)
  5.     If (dt < dtMin) Then
  6.         TextBox1.ForeColor = vbRed
  7.     Else
  8.         TextBox1.ForeColor = vbBlack
  9.     End If

Thanks SammyB,
But my problem is not in the form. How to add this property in data report.
Thanks
Mar 26 '07 #4

Dököll
Expert 100+
P: 2,364
Hi, Please anyone out there can help me!!!!!!!!!!!!
I am building a Data Report in vb6. To make it simple there a three text box on the Report. First for (Date), Second for (In-Time) and the third for (Out-Time). The data is being filled in the text box from SQL Database.
What i want is to put condition that if (In-Time) is greater than e.g. 07:30 then the time diplayed in the text box must be RED in color in the report. Likewise if the (In-Time) is less than 07:30 the text color should be Black color.

Thanks a Zillion!!!!!!!!!!!!!!!!!!!!!!!
OK, let me think a minute. What format do you want this report to come in? I am sure there's a number of ways to achieve this. Have you searched here for an answer?

I know a DataReport can come in without the help of Data Environment, I'd have to look to really tell you. DataReport also comes in MS Word format, no texboxes though, so no joy there. Can you tell us a little more?
Mar 27 '07 #5

pureenhanoi
100+
P: 175
Thanks SammyB,
But my problem is not in the form. How to add this property in data report.
Thanks
I think this can help you:
Each DataReport have Secions (example: Report Header = Section4; you can see it when open report designer)
Each Section has an array called: Controls(). If you put a control in this section, it will be added in to Controls() array, and you can call-out this control by it's index. (the first control which you put will have index=0 and so on..).
So, to change its color, you need some codes like this:
rptData.Sections(1).Controls(1).BackColor = ...
or rptData.Sections(1).Controls(1).ForeColor = ...
Controls in DataReport have properties like in Forms, and you can use Caption Property or Text Property to make conditions
Good lucks
Mar 27 '07 #6

pureenhanoi
100+
P: 175
Thanks SammyB,
But my problem is not in the form. How to add this property in data report.
Thanks
I think this can help you:
Each DataReport have Secions (example: Report Header = Section4; you can see it when open report designer)
Each Section has an array called: Controls(). If you put a control in this section, it will be added in to Controls() array, and you can call-out this control by it's index. (the first control which you put will have index=0 and so on..).
So, to change its color, you need some codes like this:
rptData.Sections(1).Controls(1).BackColor = ...
or rptData.Sections(1).Controls(1).ForeColor = ...
Controls in DataReport have properties like in Forms( and you can use Caption Property or Text Property to make conditions) . One diffrent thing that: you can't call it by name. You must call it by index, so, you should remember which you put in Sections first
Good lucks
Mar 27 '07 #7

Dököll
Expert 100+
P: 2,364
Are you hoping to bring an SQL database report to VB?
In other words, are you saying the textboxes are in fact on your database and of it and not VB?
Mar 28 '07 #8

P: 5
Hi Dököll;
ok let me explain to you in detail.
First lets talk about my FORM. I am getting data from the SQL Database in my form. I have some text boxes and MSFlexGrid. I populate the MSFlexgrid and i have made a small function called ChangeFlexgridcolor. In my form evey thing is fine. If the time is less than 07:30 the text color in the MSFlexGrid remains black. And if more than 07:30 the text of the time in MSFlexGrid changes to RED. Now to print this MSFlexGrid i have used PrintForm method. But here the problem is that it does not print entire records from the MSFlexGrid.
So i decided to use DataReport with DataEnvironment. I can view the data in my Report from the SQL Database. The only problem i have is how to call the Changetextcolor function in the Report. The report is displayed correctly but the color does not change as it changes in the MSFlexGrid in my form. Morover i need to add a label in the report that displays the department name from the database at runtime.
Plz help me out!!!
Once agian THANKS for CONSIDERING my request and sparing your valuable time for me.
Take care and hope to hear from you soon!
irfi
Mar 29 '07 #9

P: 5
Thanks pureenhanoi i will check and get back to you
Thanks again!!!
Mar 29 '07 #10

Dököll
Expert 100+
P: 2,364
Hi Dököll;
ok let me explain to you in detail.
First lets talk about my FORM. I am getting data from the SQL Database in my form. I have some text boxes and MSFlexGrid. I populate the MSFlexgrid and i have made a small function called ChangeFlexgridcolor. In my form evey thing is fine. If the time is less than 07:30 the text color in the MSFlexGrid remains black. And if more than 07:30 the text of the time in MSFlexGrid changes to RED. Now to print this MSFlexGrid i have used PrintForm method. But here the problem is that it does not print entire records from the MSFlexGrid.
So i decided to use DataReport with DataEnvironment. I can view the data in my Report from the SQL Database. The only problem i have is how to call the Changetextcolor function in the Report. The report is displayed correctly but the color does not change as it changes in the MSFlexGrid in my form. Morover i need to add a label in the report that displays the department name from the database at runtime.
Plz help me out!!!
Once agian THANKS for CONSIDERING my request and sparing your valuable time for me.
Take care and hope to hear from you soon!
irfi
With all honesty, I am no sure how this can be achieved through DataReport/Data Environmt. My way of doing this does not allow textboxes to be carried over. I attempted to fetch some things for you to no avail. I was able to find an example similar to my DataReport type. Have a look:

http://www.dreamincode.net/forums/showtopic13544.htm

Give above time to load, snapshots included. Continue asking questions, we'll ge there...
Apr 3 '07 #11

P: 1
I have the same situation on different requirement. I want to display RptTextbox object dynamicaly with 2 differnt font setting based on the one of the row object value. Would like to know.. How to access/control each row object (ie RptTextbox) in Detail Section of the data report. i can access the Detail Section object like below...

Section("xys_detail").controls("name_rptTxtbox").v isible=false.

Here it is hiding all the rpttxtboxes, whereas, i want to hide few textboxes based on some condition. Additional to this query..

how to get the value/text of RptTextbox of DetailSection that bind with DataField.

thanks in advance.
May 11 '07 #12

AlninlA
P: 1
Hi, Please anyone out there can help me!!!!!!!!!!!!
I am building a Data Report in vb6. To make it simple there a three text box on the Report. First for (Date), Second for (In-Time) and the third for (Out-Time). The data is being filled in the text box from SQL Database.
What i want is to put condition that if (In-Time) is greater than e.g. 07:30 then the time diplayed in the text box must be RED in color in the report. Likewise if the (In-Time) is less than 07:30 the text color should be Black color.

Thanks a Zillion!!!!!!!!!!!!!!!!!!!!!!!
  • Try to break 1 label to 2 label with different foreground color then place them at same position (overlay). You'd change your sql to seperate data to these labels like In-Time data to label1 and another to label2
  • This could make a lot of work to do but i've no any idea to find out that datareport can do a conditioning format.
  • This may help you = good luck for all
Feb 25 '08 #13

P: 1
@AlninlA
I have been following this thread because i also wanted the answer for similar kind of problem. I tried a lot but i could not get the solution at last i created two field for two different conditions in the table and attached them to data report texboxes one another one by overlaping and set the desired properties and made one field empty when its condition is false ; hence which ever textbox is filled it shows its colour and other texbox will be hide automatically because it is empty.

i think you should also use this kind of technique because as per my experience we cannot change texbox properties for perticular records at runtime.

Thank you.
Jan 4 '14 #14

P: 1
DataReport5.Sections("Section1").Controls.Item("co lumnname").ForeColor = rgbRed
Jan 16 '14 #15

Post your reply

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