A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

wildcards in an If statement



 
 
Thread Tools Display Modes
  #1  
Old October 26th, 2009, 07:29 PM posted to microsoft.public.access.forms
Justin
external usenet poster
 
Posts: 27
Default wildcards in an If statement

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
  #2  
Old October 26th, 2009, 07:37 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default wildcards in an If statement

"Justin" wrote in message
...
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*")


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

(please reply to the newsgroup)

  #3  
Old October 26th, 2009, 08:06 PM posted to microsoft.public.access.forms
Justin
external usenet poster
 
Posts: 27
Default wildcards in an If statement

On Oct 26, 3:37*pm, "Dirk Goldgar"
wrote:
"Justin" wrote in message

...

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*")

--
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
  #4  
Old October 26th, 2009, 09:15 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default wildcards in an If statement

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)


--
Dave Hargis, Microsoft Access MVP


"Justin" wrote:

On Oct 26, 3:37 pm, "Dirk Goldgar"
wrote:
"Justin" wrote in message

...

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*")

--
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
.

  #5  
Old October 26th, 2009, 09:48 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default wildcards in an If statement

"Klatuu" wrote in message
...
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.

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

(please reply to the newsgroup)

  #6  
Old October 27th, 2009, 07:37 PM posted to microsoft.public.access.forms
Justin
external usenet poster
 
Posts: 27
Default wildcards in an If statement

On Oct 26, 5:48*pm, "Dirk Goldgar"
wrote:
"Klatuu" wrote in message

...

You could save a bit of typing and make adding additional critera easier.

  #7  
Old October 29th, 2009, 12:03 PM posted to microsoft.public.access.forms
Justin
external usenet poster
 
Posts: 27
Default wildcards in an If statement

On Oct 27, 3:37*pm, Justin wrote:
On Oct 26, 5:48*pm, "Dirk Goldgar"



wrote:
"Klatuu" wrote in message


...


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.


--
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 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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:35 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.