vb6 Data Report - Change text color at Runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irfi
    New Member
    • Mar 2007
    • 5

    vb6 Data Report - Change text color at Runtime

    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!!!!!!!! !!!!!!!!!!!!!!!
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    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

    Code:
    Private Sub SearchData_click()
    
    ....your existing code goes here
        
        If Label1.Caption > 7:30 Then
        Label_Value = "BLUE"                     
        Label_BG.Change_It
        
        ElseIf Label1.Caption < 7:30 Then
        Label_Value = "BLACK"                 
        Label_BG.Change_It
       
        End If
    
    End Sub
    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

    Code:
    Public Label_Value As String
    
    Public Sub Change_IT()
    
        If UCase(Label_Value ) = "BLUE" Then               
        Form1.Label1.BackColor = &HFF0000
        ElseIf UCase(Label_Value ) = "BLACK" Then        
        Form1.Label1.BackColor = &000000
                         
        End If
    End Sub
    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

    Comment

    • SammyB
      Recognized Expert Contributor
      • Mar 2007
      • 807

      #3
      Originally posted by irfi
      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.
      Code:
      	Dim dt As Date
      	Dim dtMin As Date
      	dtMin = CDate("7:30")
      	dt = CDate(TextBox1.Text)
      	If (dt < dtMin) Then
      		TextBox1.ForeColor = vbRed
      	Else
      		TextBox1.ForeColor = vbBlack
      	End If

      Comment

      • irfi
        New Member
        • Mar 2007
        • 5

        #4
        Originally posted by SammyB
        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.
        Code:
        	Dim dt As Date
        	Dim dtMin As Date
        	dtMin = CDate("7:30")
        	dt = CDate(TextBox1.Text)
        	If (dt < dtMin) Then
        		TextBox1.ForeColor = vbRed
        	Else
        		TextBox1.ForeColor = vbBlack
        	End If

        Thanks SammyB,
        But my problem is not in the form. How to add this property in data report.
        Thanks

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          Originally posted by irfi
          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?

          Comment

          • pureenhanoi
            New Member
            • Mar 2007
            • 175

            #6
            Originally posted by irfi
            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.Section s(1).Controls(1 ).BackColor = ...
            or rptData.Section s(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

            Comment

            • pureenhanoi
              New Member
              • Mar 2007
              • 175

              #7
              Originally posted by irfi
              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.Section s(1).Controls(1 ).BackColor = ...
              or rptData.Section s(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

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                #8
                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?

                Comment

                • irfi
                  New Member
                  • Mar 2007
                  • 5

                  #9
                  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 ChangeFlexgridc olor. 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

                  Comment

                  • irfi
                    New Member
                    • Mar 2007
                    • 5

                    #10
                    Thanks pureenhanoi i will check and get back to you
                    Thanks again!!!

                    Comment

                    • Dököll
                      Recognized Expert Top Contributor
                      • Nov 2006
                      • 2379

                      #11
                      Originally posted by irfi
                      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 ChangeFlexgridc olor. 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:



                      Give above time to load, snapshots included. Continue asking questions, we'll ge there...

                      Comment

                      • wahab
                        New Member
                        • May 2007
                        • 1

                        #12
                        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_de tail").controls ("name_rptTxtbo x").visible=fal se.

                        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.

                        Comment

                        • AlninlA
                          New Member
                          • Feb 2008
                          • 1

                          #13
                          Originally posted by irfi
                          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

                          Comment

                          • KGIRIDHARRAO
                            New Member
                            • Jan 2014
                            • 1

                            #14
                            Giri

                            Originally posted by AlninlA
                            • 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
                            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.

                            Comment

                            • asontakke87
                              New Member
                              • Jan 2014
                              • 1

                              #15
                              DataReport5.Sec tions("Section1 ").Controls.Ite m("columnname") .ForeColor = rgbRed

                              Comment

                              Working...