Textbox dependent on Listbox values

M

mb

Can someone help me write a code that basically says this:

If [MyTxtbox] does not equal any value in [MyLstBox] Then
Msgbox "That value does not exist. Please try another value."

I need to have both the Listbox and the Textbox on my form, but I can't
figure out a code that will check the new value of the textbox if it's been
changed after the first msgbox.
 
M

mscertified

You are approaching this wrong. Never allow a user to enter a value that must
then be checked against a fixed set of values. Always force the user to
select the value from the fixed set in the first place.
A classic exampe of this is what you gave; another example would be a date.
Dates should never be entered but always picked from a calendar.

-Dorian
 
M

mb

Ok. I've changed the listbox to a combobox to do what you've suggested.
Now, is there a way to do either (or all) of the following:

1. Remove the drop down arrow to force users to type the text instead of
just scrolling through and selecting from the long list?
2. Customize my own error message if the user selects a value that's not in
the list?

Thanks for your help. :)

mscertified said:
You are approaching this wrong. Never allow a user to enter a value that must
then be checked against a fixed set of values. Always force the user to
select the value from the fixed set in the first place.
A classic exampe of this is what you gave; another example would be a date.
Dates should never be entered but always picked from a calendar.

-Dorian

mb said:
Can someone help me write a code that basically says this:

If [MyTxtbox] does not equal any value in [MyLstBox] Then
Msgbox "That value does not exist. Please try another value."

I need to have both the Listbox and the Textbox on my form, but I can't
figure out a code that will check the new value of the textbox if it's been
changed after the first msgbox.
 
B

BruceM

I'm inclined to agree in general with your comment about the OP's specific
question, but I disagree strongly with your "never" and "always" assertions
about populating a date field. In a web page or other situation where there
will be users of all levels and there is considerable risk of a data being
entered incorrectly, I can see your point, but I would not ask a competent
user who can enter the date in a second or two to scroll through a calendar
control (particularly for a date several months or years removed from the
current one) or pick year/month/day from separate drop-down lists.

mscertified said:
You are approaching this wrong. Never allow a user to enter a value that
must
then be checked against a fixed set of values. Always force the user to
select the value from the fixed set in the first place.
A classic exampe of this is what you gave; another example would be a
date.
Dates should never be entered but always picked from a calendar.

-Dorian

mb said:
Can someone help me write a code that basically says this:

If [MyTxtbox] does not equal any value in [MyLstBox] Then
Msgbox "That value does not exist. Please try another value."

I need to have both the Listbox and the Textbox on my form, but I can't
figure out a code that will check the new value of the textbox if it's
been
changed after the first msgbox.
 
B

Beetle

Maybe you could elaborate a little on what exactly you are trying to
do. On the surface it would seem to make no sense to present the
user with a list of choices, but then not allow them to choose from the
list.

--
_________

Sean Bailey


mb said:
Ok. I've changed the listbox to a combobox to do what you've suggested.
Now, is there a way to do either (or all) of the following:

1. Remove the drop down arrow to force users to type the text instead of
just scrolling through and selecting from the long list?
2. Customize my own error message if the user selects a value that's not in
the list?

Thanks for your help. :)

mscertified said:
You are approaching this wrong. Never allow a user to enter a value that must
then be checked against a fixed set of values. Always force the user to
select the value from the fixed set in the first place.
A classic exampe of this is what you gave; another example would be a date.
Dates should never be entered but always picked from a calendar.

-Dorian

mb said:
Can someone help me write a code that basically says this:

If [MyTxtbox] does not equal any value in [MyLstBox] Then
Msgbox "That value does not exist. Please try another value."

I need to have both the Listbox and the Textbox on my form, but I can't
figure out a code that will check the new value of the textbox if it's been
changed after the first msgbox.
 
M

mb

Sorry for the confusion. I was able to figure out the custom error message.
What happened next is I resized the box and the arrow was no longer the same
height as the box itself (it's only half as tall), so I was wondering if I
could possibly eliminate the arrow altogether (maybe set it's height to 0").
Then the drop down list would only appear when the user starts typing.

Beetle said:
Maybe you could elaborate a little on what exactly you are trying to
do. On the surface it would seem to make no sense to present the
user with a list of choices, but then not allow them to choose from the
list.

--
_________

Sean Bailey


mb said:
Ok. I've changed the listbox to a combobox to do what you've suggested.
Now, is there a way to do either (or all) of the following:

1. Remove the drop down arrow to force users to type the text instead of
just scrolling through and selecting from the long list?
2. Customize my own error message if the user selects a value that's not in
the list?

Thanks for your help. :)

mscertified said:
You are approaching this wrong. Never allow a user to enter a value that must
then be checked against a fixed set of values. Always force the user to
select the value from the fixed set in the first place.
A classic exampe of this is what you gave; another example would be a date.
Dates should never be entered but always picked from a calendar.

-Dorian

:

Can someone help me write a code that basically says this:

If [MyTxtbox] does not equal any value in [MyLstBox] Then
Msgbox "That value does not exist. Please try another value."

I need to have both the Listbox and the Textbox on my form, but I can't
figure out a code that will check the new value of the textbox if it's been
changed after the first msgbox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top