Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Coloring background of text and comboboxes (Access 2003/2002)

    <P ID="edit" class=small>(Edited by patt on 24-Jan-06 14:27. Testing with an input mask fouls it up)</P>Can the following be done.
    1. Show the background of all text boxes and combo boxes to yellow if blank and white if not blank, I know this can be done. This would be in the OnCurrent event I would assume.
    2. When a control is exitted or a KeyUp event has happened to a text box or combo box on the form then the above condition would be performed.
    Question: Is there a way to determine what the name of the control is that the keyup event occured.

    The point of all this is to cut down on the code for OnChange and/or AfterUpdate event of some 26 controls on this form. If I can do 1. above in a loop in the OnCurrent event (I am assuming here) then put some code in the Form's KeyUp event to do 2. above that would be a great way to go.

    I have tried this but where a control has an input mask it does not want to work. If I have a mask for a date like 99/99/00;0 then it stops on the first / and refuses to go any further.

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    The original post 359908 sorry for the copy of post.

    HanV gave this I like it better then Conditional Format

    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.

    Regards,
    Hans
    threecrow

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

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Thanks for that, in the meantime the client has said not to worry about it.

    The problem with your solution is that I would have to define those 2 events for each of 26 controls. That's why I wanted to see if it could be done with a key press on the form, but alas that falls down because it fails on the Input mask for dates. If that had have worked all I would have needed would be one event, the FormKeyUp event and a routine like you suggested, I had already written one like that.

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    No, Patt, what you need to do is create a textbox class and a combobox class with these events in them. Then bind each control in question to an instance of the appropriate class. After that, the class module will take care of the handling. The code required in the form is the code to instantiate each control variable as an instance of the class in question.
    Charlotte

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    I don't understand what you are saying or where to even start. I have never dealt with classes before.

    Would you give an example of what you mean.

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Here's an example of sorts. I has two classes, a clsForm for the form itself, and a clsComboBox for the combobox control. The form contains code to bind it to clsForm and clsForm contains code to bind the combobox control to clsComboBox. You could use code in clsForm to loop through each control on the form and bind it to a clsComboBox or a clsTextBox to control the appearance and/or behavior of the controls. Play around with it a bit and see if it gives you any ideas.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Thanks Charlotte, I will muck around with it and see what I can come up with.

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Hi Charlotte

    This is a great example of using a class module.

    I have looked at a few other examples in the past, however they were never revelant to what I wanted to accomplish.

    Yours is a good example, I can almost follow it.

    I don

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    There are a lot of ways to work with classes and they don't all require class modules, since every form and report is also a class object. The key to working with classes is WithEvents, and you can find a lot of discussion and examples by searching on that keyword. Here's a demo in A97 format (to keep it under the size limit for attachments) that shows how to use the class modules of forms and reports with the WithEvents keyword. The principles are the same as for freestanding classes. This works in 97 and above.
    Charlotte

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Hi Charlotte

    Thanks for your sample db, here is another one I found:

    Use Classes to Enhance List and Combo Boxes in Access 97, By Jim Ferguson
    http://www.fmsinc.com/tpapers/97classes/index.html

    John

  11. #11
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Hi Charlotte, I have been experimenting with your example and I want to include Text boxes as well. However, I cannot seem to define a variable as a clsTextBox as you showed for a combobox which is clsComboBox. I get a compile error on the clsTextBox variable.

    Can you tell me how to do this please.

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    You have to create a textbox custom class before you can declare a variable as being that type. I've attached clsTextBox code to get you started. Just paste it into a class module and name it clsTextBox.
    Charlotte

  13. #13
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    I put that code into a module all by itself and get a compile error on:
    Private <font color=blue>WithEvents</font color=blue> mtxt As Access.TextBox
    with the blue highlight on the word <font color=blue>WithEvents</font color=blue>.

    Am I missing a reference?

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

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    Did you create a class module, as Charlotte suggested?

  15. #15
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Coloring background of text and comboboxes (Access 2003/2002)

    How do you create a class module?

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
  •