Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2012
    Posts
    18

    Question Unanswered: SetFocus using Form Event

    I have looked everywhere and tried for several days and cannot get Access 2003 to do what I want. I have a form that has an auto number ID that is set to disabled. I have the Form's On Load event to set the record to always be a "new record". The first field on the form after the ID is called RequestedBy. I have the field set to where the background color is yellow when he field is "active". When the form is opened, I want the this field to be the first field the user enters. I want the cursor to be on this field and the background color to go from white to yellow so the user knows they are on this field without them having to click anything.

    I have tried using the DoCmd.GoToRecord in the Forms Events - On Load, On Current, After Layout and After Render to no Success. I have also tried different events under the ID field to no success. I have tried using the GetFocus command to no success.

    Could someone please tell me the "secret" to making this work? I am relatively new to Access so I need to know what the exact code is and what "event" I need to put it into. Thank you for your assistance.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's an example for a TextBox named "Text_Town":
    Code:
    Private Sub Form_Current()
    
        Me.Text_Town.SetFocus
        
    End Sub
    
    Private Sub Text_Town_GotFocus()
    
        Me.Text_Town.BackColor = vbYellow
        
    End Sub
    
    Private Sub Text_Town_LostFocus()
    
        Me.Text_Town.BackColor = vbWhite
    
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Jan 2012
    Posts
    18
    On the Form under the Event "On Current" I put in the following code:

    Private Sub Form_Current()
    Me.RequestedBy.SetFocus
    End Sub

    When I execute it I get the following error message:

    Compile error
    Method or data member not found.

    Thx.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Is "RequestedBy" a textbox control of the form and is it enabled?
    Have a nice day!

  5. #5
    Join Date
    Jan 2012
    Posts
    18
    The field is a Combo Box and is enabled.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Provided that you changed "Text_Town" to "RequestedBy" everywhere in the code I posted, I dont see any reason why it should not work. Can you compile the project without error?
    Have a nice day!

  7. #7
    Join Date
    Jan 2012
    Posts
    18

    Problem Fixed!

    Chalk it up to me having a splitting migraine last night. I had a typo in my code that was causing it not to see the correct variable. Changed it this morning and it is working like I want it to. Thank you for your help and now on to my next issue (which is posted in another thread).

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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