Share via

got focus() or lost focus()

Anonymous
2010-12-24T11:44:36+00:00

hiii morning

could you please tell me how to code in VBA if i am working in the form field so it's color should turn blue and when i move to next field then it should be white again.

thankx

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2010-12-24T12:27:22+00:00

You don't need VBA for that - you can use conditional formatting.

Open the form in design view.

Select the text box or combo box.

Select Format | Conditional Formatting...

Select Field has Focus from the dropdown under Condition 1.

Specify the formatting that you want (blue)

Click OK twice.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

6 additional answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2010-12-24T15:04:10+00:00

    Thanks, my memory of Access 2003 and before is fading.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-12-24T14:20:47+00:00

    Not only will Hans' approach do the job without code, but you can, in Design View , select all Textboxes you want this behavior to occur in then go thru the steps given above once, rather than having to put code in the GotFocus/LostFocus events of each separate control.

    Also, for Datasheet and Continuous View Forms Conditional Formatting is the only way to perform this kind of formatting.

    BTW, in 2003 there is no Click Format step, you simply specify the formatting that you want. And you only need toClick OK once. Hans apparently is running a version other than 2003.

    Linq ;0)>


    There's always more than one way to skin a cat!

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2010-12-24T12:43:36+00:00

    Why not? It's a much easier way to change the color of a control while it has the focus than using VBA.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-12-24T12:36:25+00:00

    sorry i don't need any conditional format.

    Was this answer helpful?

    0 comments No comments