Re: Change textbox color based on matching value in different textbox
- From: "CompleteNewb" <CompleteNewb@xxxxxxxxxxx>
- Date: Thu, 15 Nov 2007 19:59:56 -0500
I appreciate your response.
I don't know much, but I'm curious as to why, if declaring the vbwhite and
vbblack variables are the problem, the presented code did indeed turn all
the textboxes' background color to black.
It seems if needing the colors to be declared as variables was the problem,
wouldn't I get an error or something before the textboxes turned black?
What I'm trying to do is turn the back color of all the textboxes on the
form (and I see your point here about how the checker control is ALSO a
textbox, and so I need to exclude it from the loop) to black if the leftmost
2 characters of their contents match the leftmost two characters in the
checker textbox.
Some of the textboxes may indeed have less than 2 characters. In fact, some
of them could be null (or ""). But in the past with similar projects I have
tested for that eventuality, and in the checking of whether or not the left
2 characters match, having null doesn't error out the code, it just seems to
recognize that Null or "" don't match what's in checker, and act accordingly
(ie. if a textbox is blank, its left 2 characters DON'T match, so it
continues).
Thanks again.
"mscertified" <rupert@xxxxxxxxxxxxx> wrote in message
news:3835DD8F-58AC-40F4-9B4E-E6E2A9EC4780@xxxxxxxxxxxxxxxx
I dont see how this code works at all, surely you need variables vbWhite
and
vbBlack.
Then you also have the problem that your checker control is also a textbox
so will be hit in the loop.
Do any of the textboxes have less than 2 characters in them?
Do you know how to use debug to step through one statement at a time?
Its a weird thing you are doing, what is the point of it?
-Dorian
"CompleteNewb" wrote:
Hi all. After some useless experimentation, here I am AGAIN. I swear,
every time I think I'll be able to work my way through something, I get
NOwhere.
I'm using Access 2003 SP2 on a Windows XP Home OS.
I have a form with several hundred textboxes on it. They are currently
unbound, but will eventually be bound, I think, depending on whether I
can
do what I'm trying to do right now.
I have 1 specific textbox (named "checker" in its properties), and upon
clicking a button, I want to cycle through all the other textboxes, and
if
the 2 leftmost characters in the box are the same as the 2 leftmost
characters in checker, I want to turn that textbox's back color to black.
I tried doing a For Each, as below:
Dim txtbx As TextBox
For Each txtbx In Me
If Left(txtbx.Value, 2) = Left(Me.checker.Value, 2) Then
txtbx.BackColor = black
Else
txtbx.BackColor = white
End If
Next txtbx
This actually turns all of the textboxes black, regardless of their
values
as they compare to checker's values, then ends with a type mismatch. I
thought using .text instead of .value would fix the type mismatch, but
then
I get a "can't refer to a property of a control unless it has the focus"
error, without anything changing color.
I can't figure out why everyhting would turn black, even if the 2 left
characters DON'T match what's in checker, and then I also don't
understand
why I'd get a type mismatch (they're all just unbound textboxes, and like
I
said, I tried using .text instead of .value, but that obviously was even
worse).
Can anyone tell me how I can do this?
Any help appreciated, and thanks for taking the time to read and
(hopefully)
help.
.
- References:
- Change textbox color based on matching value in different textbox
- From: CompleteNewb
- RE: Change textbox color based on matching value in different textbox
- From: mscertified
- Change textbox color based on matching value in different textbox
- Prev by Date: RE: Change textbox color based on matching value in different textbox
- Next by Date: Re: unload event and change to design mode
- Previous by thread: RE: Change textbox color based on matching value in different textbox
- Next by thread: Re: Change textbox color based on matching value in different textbox
- Index(es):
Relevant Pages
|