 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 16th, 2003, 11:23 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
changing the backcolor property of the textbox
Hi everyone,
does anyone know how to change the backcolor property of the textbox...so everytime users want to input information on the textbox...the backcolor change to other color instead of white...indicating the active textbox they have to fill in..
any help is greatly appreciated :)
hth
fehrer
|
|

December 16th, 2003, 12:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
On the textbox's On Got Focus Event, change its backcolor to the desired color (e.g. vbYellow) and then change the rest to the other (e.g. vbWhite) by cycling through the textbox controls on the form. This will give you the gist of it... I've not tried it.
Code:
Dim ctlMyControl as Control
'This loop will turn all backcolors to white.
For Each ctlMyControl in Me
If ctlMyControl.ControlType = acTextBox Then
ctlMyControl.BackColor = vbWhite
End If
Next ctlMyControl
'This will turn that one textbox backcolor to yellow.
Me.txtMyTextBox.BackColor = vbYellow
If you put this code in each textbox's On Got Focus event, remember to change the last line so that you turn only the interested textbox yellow each time.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

December 16th, 2003, 08:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Greg,
Nice little bit of code you've got there - and yes, it does work correctly.
One thing I'd consider changing is instead of explicitly referring to the textbox, use the ActiveControl property, then just referring to the generic code - so you get something like:
Code:
Function ChangeClr()
Dim ctlMyControl as Control
'This loop will turn all backcolors to white.
For Each ctlMyControl in Me
If ctlMyControl.ControlType = acTextBox Then
ctlMyControl.BackColor = vbWhite
End If
Next ctlMyControl
'This will turn that one textbox backcolor to yellow.
Me.ActiveControl.BackColor = vbYellow
End Function
This way, rather than have Event Procedures for each textbox, you can just select them all, then put
In the On Got Focus property, as an expression.
Works a treat
Steven
I am a loud man with a very large hat. This means I am in charge
|
|

December 16th, 2003, 08:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
And then there's another option of making it a public function that can be accessed by all forms, by using Screen rather than Me
Steven
I am a loud man with a very large hat. This means I am in charge
|
|

December 16th, 2003, 11:24 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Have you tried using [u] Conditional Formatting </u>from the user interface?
From the Design view, highlight the text box and select "Format\Conditional Formatting". When the dialog box comes up, go to the combo box marked "Condition 1" and select "Field in Focus". Go to the right and select your background color, bold/unbold, font color, etc. When you are done, click OK. Go to the form view and click from another control to your text box. If you did it correctly, the attributes will change when your text box has the focus.
Sure beats programming!
Hope this helps! :)
--- Tom
|
|

December 17th, 2003, 05:36 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Beats programming!?!?!?!
Blasphemy!!!
Although - you do have a point - and now that I've noticed it - generally I abhor most UI tools - but this one certainly does the trick
Steven
I am a loud man with a very large hat. This means I am in charge
|
|

December 17th, 2003, 07:53 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi greg,
thanks for the help...very nice and neat coding...it works very well for the textbox and greatly appreciated....:)...
however it did not work for the combo box when users try to fill the form by selecting from the list..and it did not work either for textbox within the subform
steven & tom thanks to both of u as well...i'll try using the UI trick later for the combo box and subform
cheers,
fehrer
Quote:
quote:Originally posted by SerranoG
On the textbox's On Got Focus Event, change its backcolor to the desired color (e.g. vbYellow) and then change the rest to the other (e.g. vbWhite) by cycling through the textbox controls on the form. This will give you the gist of it... I've not tried it.
Code:
Dim ctlMyControl as Control
'This loop will turn all backcolors to white.
For Each ctlMyControl in Me
If ctlMyControl.ControlType = acTextBox Then
ctlMyControl.BackColor = vbWhite
End If
Next ctlMyControl
'This will turn that one textbox backcolor to yellow.
Me.txtMyTextBox.BackColor = vbYellow
If you put this code in each textbox's On Got Focus event, remember to change the last line so that you turn only the interested textbox yellow each time.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|
|

December 18th, 2003, 10:13 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks tom,
i've been able to change the backcolor property for textbox, combo box, and controls within the subform using the UI trick :)...it works properly
cheers,
fehrer
|
|

December 29th, 2003, 02:23 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Quote:
quote:Originally posted by Steven
Greg, Nice little bit of code you've got there - and yes, it does work correctly. One thing I'd consider changing is instead of explicitly referring to the textbox, use the ActiveControl property
|
Hey, great addition. I keep forgetting about those properties that let you know where you are NOW, e.g. ActiveControl. There's a bunch of 'em in VBA.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

April 19th, 2016, 10:59 AM
|
|
Registered User
|
|
Join Date: Apr 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
UI trick
I came across this problem but i do not know what and how to apply UI trick
Can anyone help me about this please i m using a combo box instead of a textbox
|
|
 |