Format a control

A

accessuser1308

I currently have a form with approximately 20 text fields. I would like to
find some VBA code that will allow me to format the current/active field on
the form (change border to blue and text to bold) and return to normal when
it loses focus. I know how to do this for each individual field...

Private Sub Text1_GotFocus()

Me.ActiveControl.BorderColor = vbBlue
Me.ActiveControl.BorderWidth = 2

End Sub

Private Sub Text1_LostFocus()

Text1.BorderColor = vbBlack
Text1.BorderWidth = hairline

End Sub

Is there somewhere on the form itself I can use this code, or something like
it, so I do not have to place this code in the got focus and lost focus
events of every field on the form. If I add fields at some point I don't
want to have to remember to add this code.

Thank you for your help
 
J

Jeff Boyce

I have good news and bad ...

If you want a control to "know" it has to do this, you will need to let
it/Access "know". Whether you do that by adding this code to every control
you want to have do this, or adding a value in the <Tag> property that you
then have Access check, or by creating a pair of general functions and
calling each in the Got & Lost Focus events, you still have to let Access
know.

(that was both the good and the bad news - yes you can, but YOU still have
to explain how to Access)

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top