Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Lounger
    Join Date
    Jan 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing a controls properties as it gets the focu (97 if possible)

    I want to change the border colour/background of a control on a form when it gets the focus. I know this can be done by attaching code to the Got Focus event of every control on the form.

    However, I am lazy and was wondering if there is a more elegant way to make the control stand out only when it has the focus. Any ideas?

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    The question is a bit vague. Are you talking about bound controls or unbound and on a single or continuous form? Are the controls flat or sunken or etched? And what are you trying to accomplish with this? If they are bound controls, the cursor will be in the control, so what is the purpose of the additional indication of focus?
    Charlotte

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    You will need some code. In a module, create the following functions. I've included in each the code to make the border color red when it has focus, and black when it doesn't. Add other code to suit your needs:

    Public WhenGotFocus(ctl as control)
    ctl.bordercolor = vbRed
    End Function

    Public WhenLostFocus (ctl as control)
    ctl.bordercolor = vbBlack
    end Function


    In the GotFocus (or OnEnter) property of every control, put this: =WhenGotFocus([controlname])
    (substituting the particular controlname of each control)

    Similarly, in LostFocus (or onExit) property put: =WhenLostFocus([controlname])
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    Lounger
    Join Date
    Jan 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    You are quite right it is too vauge.

    I have a large crowed form. The uses often have to leave there stations to get data. Also the tab order is not normal in that it jumps from one block of controls to another block and there are four blocks. New users are finding it difficult to use, experienced users do not want to change. To help new users I want to highlight the control that has focus. Most of the controls are bound a few are not, all are on a single form and all are flat.

    It seamed so simple when I started.

  5. #5
    Lounger
    Join Date
    Jan 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Sorry did not explain myself clearly enough. Please see above.

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    A very simple way of highlighting the control that has focus without using any code is the following:
    1. <LI>Select a number of editable controls, by click+shift click, or by drawing a rectangle about them. If you have a crowded form, it might be wise not to attempt it for all editable controls at once.
      <LI>Set their Background Color to something that attract attention without being annoying. A soft yellow or pale green or very light blue works best.
      <LI>Set their Background Style to transparent. Seems strange, but it is necessary, and it must be done after setting the background color.
    When you open the form, the editable controls will be transparent, but the control with the focus will show the specified background color. This is because a text box that has focus is never transparent.

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    >>Sorry did not explain myself clearly enough. Please see above. <<

    I understood you perfectly, and the solution I gave you solves this. It allows you to decide what method you want to use to highlight a field. For example, you could change the border color, and/or change the background color, and/or do anything else you want when a field has focus.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  8. #8
    Lounger
    Join Date
    Jul 2002
    Location
    Indianapolis, Indiana
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Mark,

    Using Access 2000 (home). When I paste the first function into a new module, I get the following error:
    Compile Error: Expected: List seperator or )

    In fact, when I pasted the function, the first line is red...indicating an error. Would the code be different for A2K? Also, I use A97 SR1 at work. Will your function work with that?

    Bob

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Oops! Left out the word "Function" from each. Should be:

    Public Function WhenGotFocus(ctl as control)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  10. #10
    Lounger
    Join Date
    Jan 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    FANTABBYTOESIE

    That's brilliant. Just the sort of fix I was looking for. Quick, no programming and you use the control setting as default! You're a star. Apologies for not replying soon I got waylaid.

  11. #11
    Lounger
    Join Date
    Jan 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Many thanks for your help. I can see that this is a very flexible and useful pair of functions. My apologies for not not replying soon but I got waylaid.

  12. #12
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Mark,

    Is that precisely the code to be entered? I still get a runtime error. I like Hans' simple solution, but in my case I don't want to return the Form BackColor. Might you re-post the complete (edited) code?
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    I don't think you understood Hans suggestion. You aren't returning the form's backcolor, you're making the rectange with a different backcolor visible by setting the control's backstyle to transparent. That shows the color of the rectangle behind it. If you get an error, you need to specify what error you got. A "runtime" error could be almost anything and we have no way of knowing what it is or what might have caused it without adequate information from you. Did you pass a control object into Mark's routine? If not, that will definitely cause an error.
    Charlotte

  14. #14
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Charlotte,

    1."You aren't returning the form's backcolor, you're making the rectange with a different backcolor visible by setting the control's backstyle to transparent" What "rectangle" would that be?

    2. I copied/pasted the code.

    Important: I'm not the sharpest tack in the box.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

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

    Re: Changing a controls properties as it gets the focu (97 if possible)

    Sorry, I was talking about Hans' instructions, not Mark's code, and I misread the instruction. In any event, if you put a rectangle behind the controls and make that rectangle white, then you will see a normal white color when the control's backstyle is set to transparent. When the control receives the focus, you would see its actual backcolor, say yellow for example, because the style temporarily changes to normal when the control gets the focus.

    You never did answer the question about passing a control into the function, though. You can't just copy and paste the code, you have to call it and give it a control to operate on.
    Charlotte

Page 1 of 2 12 LastLast

Posting Permissions

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