Results 1 to 3 of 3
  1. #1
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100

    Conditionally Formatting a SubForm's Background

    I have successfully used the code included below to change the background color of form contingent upon the team chosen in a combo box from the 16 possible teams.



    I have two questions:

    Is there a way to transfer that conditionally chosen color to the backgrounds of the 5 subforms in this form? I've not been able to work that out.

    Is there a simpler technique to get the same results on the base form conditional formatting?

    Code:
     
    Private Sub Form_Current()
     
        If Me.comboMLBTeamID.Value = 1 Then
            Me.Detail.BackColor = RGB(237, 210, 24)
     
            ElseIf Me.comboMLBTeamID.Value = 2 Then
                Me.Detail.BackColor = RGB(149, 206, 234)
            .   
            .    
            .    
            ElseIf Me.comboMLBTeamID.Value = 16 Then
                Me.Detail.BackColor = RGB(238, 188, 38)
     
            Else: Me.Detail.BackColor = -2147483633
     
        End If
     
    End Sub

  2. #2
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    OK; 21 views and no replies. Let's narrow it down.

    I want to make the background color of a subform the same as the main form and have it change with the main form as the main form changes records.

    I guessed at the syntax to make the change directly with the main form event like this:

    Code:
     
        If Me.txtMLBTeamID.Value = 1 Then
            Me.Detail.BackColor = RGB(237, 210, 24)
            Forms![frmCardHit]![subfrmCardHitLHPNO].Detail.BackColor = RGB(237, 210, 24)
     
            ElseIf Me.txtMLBTeamID.Value = 2 Then
                Me.Detail.BackColor = RGB(149, 206, 234)
                Forms![frmCardHit]![subfrmCardHitLHPNO].Detail.BackColor = RGB(149, 206, 234)
     
            'and so forth until
     
            ElseIf Me.txtMLBTeamID.Value = 16 Then
                Me.Detail.BackColor = RGB(238, 188, 38)
                Forms![frmCardHit]![subfrmCardHitLHPNO].Detail.BackColor = RGB(238, 188, 38)
     
            Else: Me.Detail.BackColor = -2147483633
     
        End If
    Didn't work.

    I tried to use this in the second command in the IF option:

    Code:
     
    Me.subformCardHitLPNO.Detail.BackColor = RGB(number,number,number)
    No go.

    I tried to copy the entire IF routine to the subform Current event but I couldn't figger out how to get it to "look back" at the main form value for the determining control.

    All suggestions are greatly appreciated!

  3. #3
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    After decades of research and billions of dollars, I found a solution!

    Code:
     
    Private Sub Form_Current()
     
        If Me.txtMLBTeamID.Value = 1 Then
            Me.Detail.BackColor = RGB(237, 210, 24)
            Forms!frmCardHit!subfrmCardHitLHPNO.Form.Section(acDetail).BackColor = RGB(237, 210, 24)
            Forms!frmCardHit!subfrmCardHitLHPRO.Form.Section(acDetail).BackColor = RGB(237, 210, 24)
            Forms!frmCardHit!subfrmCardHitRHPNO.Form.Section(acDetail).BackColor = RGB(237, 210, 24)
            Forms!frmCardHit!subfrmCardHitRHPRO.Form.Section(acDetail).BackColor = RGB(237, 210, 24)
            Forms!frmCardHit!subfrmCardHitControls.Form.Section(acDetail).BackColor = RGB(237, 210, 24)
     
            ElseIf Me.txtMLBTeamID.Value = 2 Then
                Me.Detail.BackColor = RGB(149, 206, 234)
                Forms!frmCardHit!subfrmCardHitLHPNO.Form.Section(acDetail).BackColor = RGB(149, 206, 234)
                Forms!frmCardHit!subfrmCardHitLHPRO.Form.Section(acDetail).BackColor = RGB(149, 206, 234)
                Forms!frmCardHit!subfrmCardHitRHPNO.Form.Section(acDetail).BackColor = RGB(149, 206, 234)
                Forms!frmCardHit!subfrmCardHitRHPRO.Form.Section(acDetail).BackColor = RGB(149, 206, 234)
                Forms!frmCardHit!subfrmCardHitControls.Form.Section(acDetail).BackColor = RGB(149, 206, 234)
     
    'As so forth until        
     
            ElseIf Me.txtMLBTeamID.Value = 16 Then
                Me.Detail.BackColor = RGB(238, 188, 38)
                Forms!frmCardHit!subfrmCardHitLHPNO.Form.Section(acDetail).BackColor = RGB(238, 188, 38)
                Forms!frmCardHit!subfrmCardHitLHPRO.Form.Section(acDetail).BackColor = RGB(238, 188, 38)
                Forms!frmCardHit!subfrmCardHitRHPNO.Form.Section(acDetail).BackColor = RGB(238, 188, 38)
                Forms!frmCardHit!subfrmCardHitRHPRO.Form.Section(acDetail).BackColor = RGB(238, 188, 38)
                Forms!frmCardHit!subfrmCardHitControls.Form.Section(acDetail).BackColor = RGB(238, 188, 38)
     
            Else: Me.Detail.BackColor = -2147483633
     
        End If
    End Sub
    Perserverance is the key. Especially when the forum does not come through!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Background color for fields in a subform
    By eric.opperman1@gmail.com in forum Forms
    Replies: 3
    Last Post: 03-19-2011, 07:46 PM
  2. Replies: 3
    Last Post: 02-17-2011, 10:19 AM
  3. Conditionally hide detail row in report
    By martinjamesward in forum Reports
    Replies: 5
    Last Post: 09-06-2010, 02:51 AM
  4. Linking tables conditionally
    By dcurtis in forum Access
    Replies: 1
    Last Post: 05-05-2010, 03:45 PM
  5. Replies: 0
    Last Post: 03-08-2009, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums