Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch a string from a TextBox

Status
Not open for further replies.

Body

MIS
Apr 24, 2002
2
EU
I'm working with Excel & VBA i've create a form with some text box and I would like to use the information typed inside. I've got this code :

Dim Val2 As String
Val2 = TextBox2.Text
Dim Val3 As String
Val3 = TextBox3.Text

Selection.AutoFilter
Selection.AutoFilter Field:=3, strCriteria1 ="= " & Val2 & ", Operator:=xlAnd, _
Criteria2 = " & Val3 & "

But it seems not look inside the box.

I appreciate anyhelp:
Thanks Body.
 
Hmmm - looks like you should be picking up your text from the text boxes ok but I would question your autofilter logic - it's going to return no values 'cos your using the and operator on the same field
It's like saying look at the field &quot;Fruit Names&quot; and get me all that are &quot;Apples&quot; and All that are &quot;Oranges&quot; - it won't work - you either need to use the <> (not equalto) operator for your 2nd criteria or the xlOR operator.

HTH
Geoff
 
Thanks Geoff

Well, in the same column(Fruits), I can find criteria1=Apple & criteria2=green.

so I would like to find all the green apples in the Excel table betwen differents fruits.

Body
 
Not gonna get into a discussion on whether fruit names and colours should be in different columns ;-). If you're sure it ain't the autofilter causing the problem then try prefixing Textbox2 etc with me! or yourFormName eg
me!textbox2.text or yourFormName.textbox2.text
HTH
Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top