VBA code to change the border of objects on a form ... Got / Lost focus (1 Viewer)

sjs94704

Member
Local time
Today, 09:50
Joined
May 7, 2013
Messages
41
All I want to do is create a VBA module that causes the border of a control, like a text box, to slightly change when it has the focus to prompt the user to help them know where they are on the screen. So, very simply, when a control gets the focus the border changes slightly but enough for the user to see to help them know where they are at!
 

June7

AWF VIP
Local time
Today, 08:50
Joined
Mar 9, 2014
Messages
5,473
Programmatically changing a control's properties affects ALL instances of control. So this doesn't really work for form in Continuous or Datasheet view. Consider using Conditional Formatting which can change the appearance of textbox and combobox individually for each record. Can't change border but can change background or font color or enable/disable. No VBA involved.

If form is in Single view or designed so only one record shows in Continuous view and you really want VBA, I expect would need code in both GotFocus and LostFocus events of each control.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:50
Joined
May 7, 2009
Messages
19,245
you can also use Conditional Formatting on your Textbox to change it's color when it has focus.
like on the demo on form1.
 

Attachments

  • CFTest.accdb
    392 KB · Views: 63

KitaYama

Well-known member
Local time
Tomorrow, 01:50
Joined
Jan 6, 2022
Messages
1,541
I really like what @Eugene-LS has done for highlighting active control.
No use of Conditional Formatting, not even a single line of code.

Pure control's properties.

 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 12:50
Joined
Mar 28, 2020
Messages
1,044
KitaYama, I like that particular method as well but it unfortunately does not control the border color. That's the one disadvantage of that method. But like Eugene said, options are a good thing.
 

KitaYama

Well-known member
Local time
Tomorrow, 01:50
Joined
Jan 6, 2022
Messages
1,541
unfortunately does not control the border color
I know. And I didn't mention that method at first, because it wasn't what the OP was looking for.
Since there was some suggestions about Conditional Formatting (which can't handle borders), I thought it may help in some way.

Thanks for reminding.
 

sjs94704

Member
Local time
Today, 09:50
Joined
May 7, 2013
Messages
41
What I am talking about is for data entry form. Not necessarily a continuous forms. Such as when entering customer or vendor name and addresses, etc..., but when it comes to continuous forms I get it that this would not work as mentioned previously!
 

Mike Krailo

Well-known member
Local time
Today, 12:50
Joined
Mar 28, 2020
Messages
1,044
I thought this question was already answered. Are you saying you still haven't got your border highlighting to work?
 

sjs94704

Member
Local time
Today, 09:50
Joined
May 7, 2013
Messages
41
I thought this question was already answered. Are you saying you still haven't got your border highlighting to work?
Life shows up. I am in recovery and just got elected into a new position helping people in their first few days/weels of recovery, so my attention got diverted for a minute doing that! Just getting a moment to sit back down into my own life again and get back to this...

All I was trying to clarify is that I read in a post previous to this one that someone said that changing the color would not work in continuous forms, etc. and I was just clarifying that it was not my intent to do this in that type of form, that's all.
 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 12:50
Joined
Mar 28, 2020
Messages
1,044
That's fine, I believe you have all the information you need from the previous comments. Just review the various recommendations and try to get it working.
 

Users who are viewing this thread

Top Bottom