Select Case

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Hello,

Can someone help me with Select Case statement?

I have form with text box (named txtEligible) that is
bound to certain field in a table. The User may have to
update the text box.

For varying reasons, I need to use VBA to limit what the
user can put in the text box. If the user does not enter
one of following: yes no dif add then I want message box
to appear. But I cant get the Select Case statement to
work. Below is the code. Can someone help. Thanks.

strcmbESDStaff = txtEligible

Select Case strcmbESDStaff
Case "yes"

Case "no"

Case "dif"

Case "add"

Case Else
strMSG = msgbox("Must enter one of the
following: yes no dif add.")
'End Select
 
The Select Case looks fine but the strMsg = Msgbox
statement looks dodgy. Assuming that you do not want to
take any action when a valid entry is made, try

Select Case strcmbESDStaff
Case "yes", "no", "dif", "add"
Case Else
msgbox "Must enter one of the following: yes
no dif add."
End Select

Hope This Helps
Gerald Stanley MCSD
 
Rob said:
I have form with text box (named txtEligible) that is
bound to certain field in a table. The User may have to
update the text box.

For varying reasons, I need to use VBA to limit what the
user can put in the text box. If the user does not enter
one of following: yes no dif add then I want message box
to appear. But I cant get the Select Case statement to
work. Below is the code. Can someone help. Thanks.

strcmbESDStaff = txtEligible

Select Case strcmbESDStaff
Case "yes"

Case "no"

Case "dif"

Case "add"

Case Else
strMSG = msgbox("Must enter one of the
following: yes no dif add.")
'End Select


Wouldn't it be easier to use a combo box with its
LimitToList property set to Yes?

It's not clear what you mean by "cant get the Select Case
statement to work", so I have no idea what problem needs to
be addressed.

There's nothing wrong with your code as posted, maybe you
should double check the value in the text box to make sure
that it matched the desired strings exactly??
 
Rob said:
Hello,

Can someone help me with Select Case statement?

I have form with text box (named txtEligible) that is
bound to certain field in a table. The User may have to
update the text box.

For varying reasons, I need to use VBA to limit what the
user can put in the text box. If the user does not enter
one of following: yes no dif add then I want message box
to appear. But I cant get the Select Case statement to
work. Below is the code. Can someone help. Thanks.

strcmbESDStaff = txtEligible

Select Case strcmbESDStaff
Case "yes"

Case "no"

Case "dif"

Case "add"

Case Else
strMSG = msgbox("Must enter one of the
following: yes no dif add.")
'End Select

Pardon this silly question, but if txtEligible is a text box then
strcmbESDStaff is an object, while "yes" etc. are strings. Type clash?

Dootje
(e-mail address removed)
 
"Rob"schreef
Dootje said:
Pardon this silly question, but if txtEligible is a text box then
strcmbESDStaff is an object, while "yes" etc. are strings. Type clash?


No, there is no conflict. The text box's Value property
will be used in this context because that's what an
assignment statement operates on. If you want to assign one
object variable to another, you need to use a Set statement.
 
Marshall Barton said:
No, there is no conflict. The text box's Value property
will be used in this context because that's what an
assignment statement operates on. If you want to assign one
object variable to another, you need to use a Set statement.

Marsh,

Thanks for clearing that up. Will make my future coding easier to read!

Dootje
(e-mail address removed)
 
Back
Top