Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Controls (97sr2b)

    Is there a simple way of changing the background color, in the a form control that gets the focus. I would like to do this on all forms.

    example: at present background color=white when control gets the focus background color=yellow
    threecrow

    Don't make excuses. It's what you do, not why you didn't.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Controls (97sr2b)

    In Access 2000 and later, this can be done by applying conditional formatting. Here is a method for Access 97:

    Put the following function in a standard module:

    Private Function SetBackground(OnOff As Boolean)
    On Error Resume Next
    If OnOff = True Then
    Screen.ActiveControl.BackColor = vbYellow
    Else
    Screen.ActiveControl.BackColor = vbWhite
    End If
    End Function

    Open a form in design view.
    Select all text boxes and combo boxes you want to apply the background color handling to.
    Activate the Event tab of the Properties window.
    Click in the On Got Focus event, and enter this: =SetBackground(True) then press Enter.
    In the On Lost Focus event, enter =SetBackGround(False) and press Enter.
    Close and save the form.
    Repeat for other forms.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Controls (97sr2b)

    Thank you kindly Hans I'll get this a shot. A lot easier than my idea
    threecrow

    Don't make excuses. It's what you do, not why you didn't.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Form Controls (97sr2b)

    Hans,

    FYI, I used to use a similar technique in Access97 in which I referenced the ActiveControl in the function. However, I found that this sometimes didn't work properly, especially for the 1st control on the form when the form was first opened. I've since gone to using 2 functions in a control's Get and Lost Focus events: =SetKeyinBackcolor([ActiveControl]) and =ResetBackcolor([ActiveControl]). These always seem to work properly.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Controls (97sr2b)

    Hi Hans

    How would you adapt above code for a Continous Form so color in just the active field in active row is changed?

    Thanks, John

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Controls (97sr2b)

    John,

    You are using Access 2000. The easiest way there is to use conditional formatting, with Has Focus as condition.

    If you need to do it for Access 97, try this:
    - Behind each text box and combo box in the detail section, put a solid white box with exactly the same position and size.
    - Select all text boxes and combo boxes in the detail section.
    - Set the Back Color to yellow.
    - Set the Back Style to transparent.
    Yes, this is necessary, strange as it may seem, and it is important that you set the background color before making the controls transparent. When a control gets the focus, it won't be transparent any more, so that the specified background color shows.

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Controls (97sr2b)

    Hi Hans

    That was simple enough.

    As it relates to Continous Forms:

    1. Are there any standardscolors/techniques that match other Microsoft products that you can offer?

    2. Do other developers have favorites that are ergonomically pleasing to the eye that they want to share?

    Thanks, John

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Controls (97sr2b)

    1. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

    2. Although I'm not overly fond of pastel tints in real life, I find they work well as background colors for forms and controls. Pale blue, pale green and pale yellow are soft on the eyes, yet offer sufficient contrast with black text, with pale yellow (RGB 255, 255, 224) is my favorite. I don't like pale magenta myself, but that is a matter of personal preference.

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

    Re: Form Controls (97sr2b)

    I like either pale yellow or pale cyan. Neither of those is particularly offensive and they seem to be easier on the eyes than some of the other tones. I'm with you on the magenta, Hans. The other thing to keep in mind is how any shade looks if someone has been playing with their Windows colors. <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15>
    Charlotte

  10. #10
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Controls (97sr2b)

    Han
    Apoligize

    Below is the code I typed into a standard module, looks just like the one you sent.
    I gave the module the of FormBackgroundColor

    Private Function SetBackground(OnOff As Boolean)
    On Error Resume Next
    If OnOff = True Then
    Screen.ActiveControl.BackColor = vbYellow
    Else
    Screen.ActiveControl.BackColor = vbWhite
    End If
    End Function

    and then in form design, the first control OnGotFocus =SetBackground(True), OnLostFocus =SetBackground(False)
    Saved.

    When the Form is opened I get and Error Message that the function can not be found.
    Did I look at the code with both of my eyes wide closed, and miss something.

    Thank You Kindly
    threecrow

    Don&#39;t make excuses. It&#39;s what you do, not why you didn&#39;t.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Controls (97sr2b)

    Sorry, my bad. Change Private Function to Public Function.

  12. #12
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Controls (97sr2b)

    If I was just a little better at code I may have seen it.

    Once again Thank You Kindly
    threecrow

    Don&#39;t make excuses. It&#39;s what you do, not why you didn&#39;t.

Posting Permissions

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