Results 1 to 6 of 6
  1. #1
    BarryW
    Guest

    Changing form background colours

    Hi to all and sundry watching/reading,

    I'm trying to alter the background colour of a continuous form (all the SAME colour) dependant upon the value that ends up in the calculated field in the footer.

    Let me explain;
    The form is a 'Daily Schedule' containing two subforms one for AM and one for PM. It is the subforms I want to change the background colour of.

    Each of the subforms lists the tasks for that session (in continuous mode). Each task has an 'Estimated Duration' and which is 'sumed' by a calculated field in the footer."(Sum[Estimated Duration])"

    If the value in this textbox (named 'Total') is 2 or above I want to change the background orange, and if it is 3 or above I want the background to go red.

    I have the VBA code, and can make the background change with a button. But I wouldn't work under the 'On_Load' event because the value is not calculated until the form has finished loading.

    Anybody got any ideas? -
    DONT SAY I SHOULD BE USING PROJECT!?! HI HI <img src=/S/brainwash.gif border=0 alt=brainwash width=15 height=15>

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing form background colours

    Hi Barry,

    According to the MS Access (2000) help files:
    <pre>When you first open a form, the following events occur in this order:

    Open

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changing form background colours

    Is this the footer of the subform or of the parent form? You could try using the subforms' OnCurrent event (use the parent form's OnCurrent if that's where the footer lives) to test whether the field in the footer has a value. If it does, then execute the code to change the backcolor.
    Charlotte

  4. #4
    BarryW
    Guest

    Re: Changing form background colours

    Firstly, thanks to Mark for the tip on the loading events, but unfortunately the 'OnCurrent' event seems to be too early as well. For some reason the field doesn't calculate its value until very late on in the form loading proceedure.

    In response to Charlottes Q. The calculated field is in the footer of the subform(s) (so that you can see how many hours you have allocated in an individual morning or afternoon).

    I'm thinking I may need somekind of 'Wait' command or delay timer, set to trigger once the OnCurrent event has finished.

    Barry

    PS. Sorry for the dreadful grammer and spelling of the last post. It was the end of a very long, and frustrating day!

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Changing form background colours

    The OnCurrent event happens over and over, which is why I suggested a test in it to see if the calculated field contained a value yet. Another way to do this would be with a DSum to return the value in the open event of the subform.
    Charlotte

  6. #6
    BarryW
    Guest

    Re: Changing form background colours

    Yeeeessssss!, sorry, that wasn't very professional was it?

    Thanks a lot Charlotte.
    I started by putting in a breakpoint, and stepping through the code, this worked, but stopped functioning when I pulled the breakpoint. So instead of taking the variable from the calculated field I did as you suggested and used a DSum, in the OnCurrent event just before the comparison routine;

    Private Sub Form_Current()

    Dim tot_allocated As Double
    tot_allocated = DSum("[Estimated Duration]", "[Daily Schedule AM]")
    'Estimated Duration as the Summed field
    'Daily Schedule AM as the Query supporting the subform

    Dim Total_Val As Double

    If Not IsNull(tot_allocated) Then
    Total_Val = tot_allocated
    If Total_Val = 2 Then
    Detail.BackColor = 33023
    ElseIf Total_Val >= 3 Then
    Detail.BackColor = vbRed
    End If
    End If


    End Sub

    ---- Sorted! ------

    My Saviours

    Barry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •