wildcards in an If statement

  • Thread starter Thread starter Justin
  • Start date Start date
J

Justin

I am trying to make a text box visible according to the value in a
combo box. I used the If statement posted in a previous post to
evaluate for a single value, but I need to show the text box if a
specific number is followed by a letter. i.e. 34A, 34B, etc. I've
tried the * and ? wildcards without success. Any help will be greatly
appreciated.

Thanks again,
Justin
 
Justin said:
I am trying to make a text box visible according to the value in a
combo box. I used the If statement posted in a previous post to
evaluate for a single value, but I need to show the text box if a
specific number is followed by a letter. i.e. 34A, 34B, etc. I've
tried the * and ? wildcards without success. Any help will be greatly
appreciated.


It would be helpful to know what you tried, but something like this should
work:

If Me.ComboBox1 Like "34*" Then
Me.TextBox2.Visible = True
Else
Me.TextBox2.Visible = False
End If

That can be simplified to:

Me.TextBox2.Visible = (Me.ComboBox1 Like "34*")
 
It would be helpful to know what you tried, but something like this should
work:

    If Me.ComboBox1 Like "34*" Then
        Me.TextBox2.Visible = True
    Else
        Me.TextBox2.Visible = False
    End If

That can be simplified to:

    Me.TextBox2.Visible = (Me.ComboBox1 Like "34*")

--
Dirk Goldgar, MS Access MVP
Access tips:www.datagnostics.com/tips.html

(please reply to the newsgroup)


Many thanks Dirk. So far this is exactly what I was after. I used the
If statement and nested several ElseIf statements to accomplish what I
wanted to do.
In case this might help others:

If Me.Route Like "34*" Then
Me.Fl_Miles.Visible = True
ElseIf Me.Route Like "31*" Then
Me.Fl_Miles.Visible = True
ElseIf Me.Route Like "63*" Then
Me.Fl_Miles.Visible = True
ElseIf Me.Route Like "69*" Then
Me.Fl_Miles.Visible = True
ElseIf Me.Route Like "60*" Then
Me.Fl_Miles.Visible = True
ElseIf Me.Route Like "85*" Then
Me.Fl_Miles.Visible = True
Else
Me.Fl_Miles.Visible = False
End If

I placed this code in the Private Sub Form_Current() section of the
form. Now I can add a few more If statements to hide/show other text
boxes.

Thanks again

Justin Thomas
 
You could save a bit of typing and make adding additional critera easier.
Here is how you could do it using the Switch function:

Me.TextBox2.Visible = Nz(switch(x like "31*",true, x like "34*", true, x
like "60*", true, x like "63*", true, x like "69*",true x like "85*"), false)
 
Klatuu said:
You could save a bit of typing and make adding additional critera easier.
Here is how you could do it using the Switch function:

Me.TextBox2.Visible = Nz(switch(x like "31*",true, x like "34*", true, x
like "60*", true, x like "63*", true, x like "69*",true x like "85*"),
false)


Good idea. I was trying to think of a concise way to express that case
structure, but I didn't think of the Switch function.
 
Good idea.  I was trying to think of a concise way to express that case
structure, but I didn't think of the Switch function.

--
Dirk Goldgar, MS Access MVP
Access tips:www.datagnostics.com/tips.html

(please reply to the newsgroup)

Thanks, Dave, I'll give that a try. I'm glad that I posted my code to
get another opinion.

Justin
 
Thanks, Dave, I'll give that a try. I'm glad that I posted my code to
get another opinion.

Justin

Thanks again, Dirk and Dave. This worked like a charm. This allowed me
to tighten up my form by placing some of the text boxes on top of each
other and having them only appear when needed.

Justin
 
Back
Top