Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub to change text box color

Status
Not open for further replies.

Seeff

Programmer
Dec 2, 2002
33
IL
I have a form with a number of text boxes. I want to write ONE sub that is called after each text box update that changes the box color. I basically need the syntax to find the current textbox name. Thanks!
 
What version of Access are you running ?

'cause if you a A2k or beyond you don't need any Subs at all. You can do it using Conditional Formatting.


G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Okay so Conditional Formatting is not an option.

The approach that the Access Menu wizard takes is for one subroutine that is called by each of the controls. The controls then pass their own name to the sub in the Call

Eg. To set the BackColour to RED as soon as a control is changed:-

Private Sub textBox1_AfterUpdate()
Call FormatTextBox(textBox1)
End Sub

Private Sub textBox2_AfterUpdate()
Call FormatTextBox(textBox2)
End Sub

Private Sub textBox3_AfterUpdate()
Call FormatTextBox(textBox3)
End Sub

Private Sub FormatTextBox(CallingObject As Control)
CallingObject.Properties("BackColor") = 255
EndSub




'ope-that-'elps.


G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Yes, that works, thanks. This is just about the same as coding the colorchange for each textbox. I thuoght there would be a far quicker way, something along the lines of:

if data in form is changed then
find textbox name
change color(text boxname)
End If
 

Yes seeff, thats true, but in the spirit of 're-usable code'

You can do a whole range of complete formatting this way and if you want to update it then there is only one place to make the change.


The problem with what you had in mind, I think, is that if you could find an event to run off, that occured every time a control was updated, then the event's own object ( the form ) would have the focus. If the form has the focus - then the individual control does not. Sorting out the code to work out which control did just have the focus would be far more conplex than the solution above.



G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Ok...you got me convinced - what a bug to code 50 text boxes.

I guess that in a nutshell, computers can think like submarines can swim!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top