Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76

    Unanswered: Form Background Colour

    Hi all,

    I am writing an application with lots of different forms. I want to be able to set the background color of ALL the forms as and when my users moan about the colour!

    I thought of setting a global CONST AllFormBackColour = vbred

    Then I thought of setting each form backcolour to AllFormBackColour. My problem is that I can not find a property for the form.backcolor. I can see me.formheader.backcolor and me.formfooter.backcolor but not for the whole form.

    Can anyone help or offer an easier way?

    Thanks
    Simon

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    There is no form backcolor, you have to set each form section individually. You've found the Header section and Footer section, you're only missing the form Detail section.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    I see now. It is:
    me.detail.backcolor and not

    me.formdetail.backcolor

    Thanks
    Simon

  4. #4
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    Do I have to set the colour for each form or can I do this by using a global constant?

    For example, i want each form to be rgb(204,255,204)

    How would I set rgbColour = rgb(204,255,204) so that in each form, I can set the colour to:
    me.formheader = rgbColour

    This will allow me to change the background colour on all of my forms simply by changing the value of rgbColour once.

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You can use a global constant, but you'll have to have code in each form's opening event to set the backcolors to the global constant.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    How would I set this global constant? I am having problems. I think this is because I have a bracket. Am I on the right lines here?

    In a module:

    Option Compare Database
    Option Explicit

    CONST fromColor as string
    formColor = RGB(204,255,204)

    Then in my forms:

    me.formfooter.backcolor = formColor

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    You cannot assign a value to a constant at run time - the clue is in the name
    You want to use a global variable.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    For future ref: I would recommend you copy and paste your exact code - there is a typo in what you have posted that would prevent it from even compiling. Finally, always handy to give specific details instead of "I am having problems". Error descriptions etc.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    Ok, please bear with me I am new to all of this.

    I have a module and in it I am trying to set a global variable:

    Option Compare Database
    Option Explicit

    Static formColor As String
    formColor = RGB(204, 255, 204)

    Then in my form open event, I have:

    Me.Detail.BackColor = formColor

    When I open the form, I get the Complie Error "Invalid outside proceedure" and my code stops on the word static.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Nope - not static - that is, as said, "Invalid outside proceedure". thanks for the error message though

    You probably could do with swotting up on declaring variables and scope etc.

    Code:
    Option Compare Database
    Option Explicit
    
    private formColour As Integer
    
    Public Function getFormColour() As Integer
    if formColour = 0 THEN formColour = RGB(204, 255, 204)
    
    getFormColour = formColour
    
    End Function
    Form open:
    Code:
    Me.Detail.BackColor = getformColour
    that's my preferred way of doing things. You are essentially creating the VBA equivalent of a static class (but that's probably a bit more information than required).

    Oh - and I corrected your spelling of colour
    Testimonial:
    pootle flump
    ur codings are working excelent.

  11. #11
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    Thanks for your help with this but I now get error 6 "Overflow" when I try to open the form.

  12. #12
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Sorry my mistake - rgb returns a 4 byte integer - it should be declared as a "long", not "integer" (integer is 2 bytes in VB). That is two changes in total - the function and the variable.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  13. #13
    Join Date
    Feb 2010
    Location
    Yorkshire UK
    Posts
    76
    Works like a dream. Thanks so much for your help and time.

Posting Permissions

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