Results 1 to 8 of 8
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    simple backcolor code ?

    i need a bit of help getting the syntax of a line of code that would change the backcolor on a subform...



    I have this, but it yields an error

    If Me.tglInstallationNoteFlag = False Then
    Me.chldInstallationNotes.Detail.BackColor = NormalColor

    many thanks in advance
    mark

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    What is NormalColor? Is that a variable you declared? What color do you want?

    There are some vb constants for a few colors
    Me.Detail.BackColor = vbWhite
    (also vbRed, vbBlack, vbBue, vbGreen, vbYellow, vbMagenta, vbCyan)

    or you can use RGB function
    Me.Detail.BackColor = RGB(204, 255, 204)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    Quote Originally Posted by June7 View Post
    What is NormalColor? Is that a variable you declared? What color do you want?

    There are some vb constants for a few colors
    Me.Detail.BackColor = vbWhite
    (also vbRed, vbBlack, vbBue, vbGreen, vbYellow, vbMagenta, vbCyan)

    or you can use RGB function
    Me.Detail.BackColor = RGB(204, 255, 204)

  4. #4
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    Sorry, I wasn't really clear
    NormalColor is a variable that I declared

    My difficulty is frying to the backcolor property of the detail section in my subform
    < me.subFormName.detail.backcolor> is resulting in am error

    The togglebutton control that fires the code to change this property is on the main form, not the subform

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Do you know that the NormalColor variable is getting populated properly?

    Reference the subform through the container control. I always name the control different from the form it holds, like: ctrInstallationNotes. Try:

    Me.containername.Form.Detail.BackColor = NormalColor
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    hmmm " container control "... totally foreign language to me (sorry)
    ____________________
    right now, with the code i've got (below) -which is calledh from the main form, and where chldInstallationNotes is the correct name of the subform, the error i'm getting is:
    '438' object doesn't support this property or method

    Me!chldInstallationNotes.Detail.BackColor = NormalColor


    there must be same way of gahnging the subform's detail's backcolor property thru code; -yes?

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Are you using a continuous form or a datasheet?

    Continuous forms are a little more malleable. I tested this with a continuous form:

    in the ON CURRENT event of the subform use this code:

    Code:
    If Forms!<main form name>!<field name> = <value> Then
        Me.Detail.BackColor = vbRed
    Else
        Me.Detail.BackColor = vbGreen
    End If
    Where main form name is the name of your main form
    field name is the name of the field with the value you want to determine conditional formatting
    value is the value you're testing to see whether or not you want to apply the coloring.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Controls are buttons, textboxes, comboboxes, listboxes, labels, etc. A subform/report container control is the control that holds an Access object (table, query, form, report). It has properties just as any other control, one of which is SourceObject. This is where you identify the table, query, or form/report as source.

    rpeare's suggestion is one approach. However, this will not change the color if you click the toggle button on the main form. For code behind the main form, refer to the subform and its properties through the container as I described earlier.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Simple code syntax question
    By mseeker22 in forum Programming
    Replies: 1
    Last Post: 07-07-2011, 03:55 AM
  2. simple VB code help
    By avworx in forum Programming
    Replies: 2
    Last Post: 03-29-2011, 07:09 PM
  3. Replies: 1
    Last Post: 10-22-2009, 03:32 AM
  4. Simple Nav Form Code Not Working
    By alsoto in forum Forms
    Replies: 10
    Last Post: 04-10-2009, 09:30 AM
  5. Replies: 0
    Last Post: 10-24-2008, 11:20 AM

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