Results 1 to 10 of 10
  1. #1
    newtoAccess is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    226

    How to have the field change colour when it is selected?

    I was told that access has the ability to have a field change colour when it is selected (click or tab) to indicate what field is selected, and then when not selected changed back to the normal colour.

    Does anyone know how to do this?

    It may have something to do with "on got focus and on lost focus"

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would agree and then put code that plays with the BackGroundColor in those events.

  3. #3
    newtoAccess is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    226
    I am new so where does the code go and what code do I use?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about you take your best guess as to what the code should look like and where it should go and then try it. Post your results and I will offer comments.

  5. #5
    newtoAccess is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    226

    her is my first try

    How about sometning like this.. I do not know wether to use vbyel or vbyellow or a code for color or even if I have to use vb at all.


    Private Sub Event_test_Main_GotFocus()
    background -Color: vbyel
    End Sub


    Private Sub Event_test_Main_Lostfocus()
    background -Color: vbWhite
    End Sub

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Not bad. If the control were named txtMover then the code would be:
    Code:
    Private Sub txtMover_GotFocus()
       Me.txtMover.BackColor = vbYellow
    End Sub
    Private Sub txtMover_LostFocus()
       Me.txtMover.BackColor = vbWhite
    End Sub

  7. #7
    newtoAccess is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    226
    It is not working perfect yet. Sometimes the lost focus does not work. The Field stays yellow and sometimes thefield does work..

    -----------------------------------

    Private Sub Cost_GotFocus()
    Me.Cost.BackColor = vbYellow
    End Sub
    Private Sub Cost_LostFocus()
    Me.Cost.BackColor = vbWhite
    End Sub
    Private Sub Date_Main_GotFocus()
    Me.Date_Main.BackColor = vbYellow
    End Sub
    Private Sub Date_Main_LostFocus()
    Me.Date_Main.BackColor = vbWhite
    End Sub
    Private Sub Event_02_GotFocus()
    Me.Date_Main.BackColor = vbYellow
    End Sub
    Private Sub Event_02_LostFocus()
    Me.Event_02.BackColor = vbWhite
    End Sub
    Private Sub Event_test_Main_GotFocus()
    Me.Event_test_Main.BackColor = vbYellow
    End Sub
    Private Sub Event_test_Main_LostFocus()
    Me.Event_test_Main.BackColor = vbWhite
    End Sub
    Private Sub Item_1_Time1_GotFocus()
    Me.Item_1_Time1.BackColor = vbYellow
    End Sub
    Private Sub Item_1_Time1_LostFocus()
    Me.Item_1_Time1.BackColor = vbWhite
    End Sub

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In order for the LostFocus event to fire you have to put the focus somewhere else that can take the focus. Maybe the OnEnter and OnExit events would work better for you. Or maybe both events.

  9. #9
    newtoAccess is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    226
    OnEnter and OnExit Do I wor the same as got focus?

    will they work on a field?
    something like this:

    Private Sub Cost_OnEnter()
    Me.Cost.BackColor = vbYellow
    End Sub

    Private Sub Cost_OnExit()
    Me.Cost.BackColor = vbWhite
    End Sub

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Just for the record, tables have fields and forms have controls. Controls can be bound to fields in the RecordSource of a form. If you go to Access help and key in events, you can see all of the events of a form and the order they occur. The answer to your question is yes.

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

Similar Threads

  1. Selected Group only in Report
    By Robert M in forum Reports
    Replies: 0
    Last Post: 09-18-2009, 08:10 AM
  2. Change the value of a field
    By akhilash in forum Queries
    Replies: 0
    Last Post: 07-16-2009, 07:20 AM
  3. Replies: 0
    Last Post: 02-12-2009, 05:23 AM
  4. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 AM
  5. Change the colour of a form background
    By r_e_v_a_n_s in forum Forms
    Replies: 0
    Last Post: 11-15-2005, 03:39 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