Re: Change textbox color based on matching value in different textbox

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.





.



Relevant Pages

  • RE: Change textbox color based on matching value in different textbox
    ... Then you also have the problem that your checker control is also a textbox ... Do any of the textboxes have less than 2 characters in them? ... I have a form with several hundred textboxes on it. ...
    (microsoft.public.access.formscoding)
  • Re: Data Validation for TextBoxes
    ... that method will not prevent users from pasting in "invalid" characters. ... Private Sub TextBox1_MouseDown(ByVal Button As Integer, ... Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) ... Also, how can I do it for many TextBoxes, ...
    (microsoft.public.excel.programming)
  • Re: Format and Inputmask Problem
    ... L and X are valid input mask characters so they can't be part of your static ... Can you more simply set this up as 4 textboxes to gather each of the numeric ... > numerical characters from the field and the hyphens and alpha ...
    (microsoft.public.fox.programmer.exchange)
  • Win32: C: Chinese language inputting improperly in text box. Extremely strange bug, please help!
    ... entering chinese ... up and puts random characters int he textbox (sometimes '?', ... For me to reproduce the symptom, i click inside the textbox, with IME ... copy those, and paste into my suspect textboxes, they show up FINE. ...
    (comp.lang.c)
  • Re: everything after character is not displayed
    ... I have been getting strange behaviour when using ' in by textboxes. ... area type is ok ... this does not happen with other characters such as " or / ...
    (comp.lang.php)