By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Search two columns data in one text box

P: 3
Expand|Select|Wrap|Line Numbers
  1. vSearchString = SearchFor.Text
this will search all field data
but I need search column1 and column2 data only
Example column1 118 column2 22
text box entering only 118 22

Expand|Select|Wrap|Line Numbers
  1. Code using:
  3. Private Sub SearchFor_Change()
  5. 'Create a string (text) variable
  6.     Dim vSearchString As String
  8. 'Populate the string variable with the text entered in the Text Box SearchFor
  9.     'vSearchString = SearchFor.Text & "*"
  11.     vSearchString = SearchFor.Text
  12.     ' vSearchString = "[PartNos] like " * " & txtBox & " * ""
  14.     'vSearchString = Len(Me!txtName.Text & "") <> 0
  15.     'btnNext.Enabled = Len(Me!txtName.Text & "") <> 0
  18. 'Pass the value contained in the string variable to the hidden text box SrchText,
  19. 'that is used as the sear4ch criteria for the Query QRY_SearchAll
  20.     SrchText.Value = vSearchString
  22. 'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
  23.     Me.SearchResults.Requery
  26. 'Tests for a trailing space and exits the sub routine at this point
  27. 'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
  28.     If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
  29.         Exit Sub
  30.     End If
  32. 'Set the focus on the first item in the list box
  33.     Me.SearchResults = Me.SearchResults.ItemData(1)
  34.     Me.SearchResults.SetFocus
  36. 'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box
  37.     DoCmd.Requery
  39. 'Returns the cursor to the the end of the text in Text Box SearchFor
  40.     Me.SearchFor.SetFocus
  42.     If Not IsNull(Len(Me.SearchFor)) Then
  43.         Me.SearchFor.SelStart = Len(Me.SearchFor)
  44.     End If
  47. End Sub
Mar 30 '18 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 2.5K+
P: 3,210

Welcome to Bytes.

First, please use the Code Tags when posting code to the forum, as this is a requirement of the site. this is the [CODE/] button in your post editor. I have edited your post above.

Second, I am not sure exactly what your question is. You seem to be explaining what your code does, but have not asked a specific question. If you clarify, we would be glad to assist you.
Mar 30 '18 #2

P: 3
I have text box called
vSearchString = SearchFor.Text

I have Table1 field

ACnumber 122
PartNos 28

I have to search this two numbers on SrchText
at present it shows all records when enter
instead 122 28
Mar 30 '18 #3

P: 3
I have to enter in that search box 122 which is in one column
and 28 is another column so it will show both columns data only instead of all data

at present when I enter 122 in that search box it will show all data

My search Criteria
Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*"

hope its clear
Mar 30 '18 #4

Expert Mod 2.5K+
P: 3,210
Unfortunately it is still not clear.

I understand there may be a language barrier here--but I am still unclear what it is you want to do.

Try to be as specific as possible as to what you are looking for.

Thank you.
Mar 30 '18 #5

Expert Mod 15k+
P: 31,419
Hi Twinny.

They want to search across two separate fields (columns) by entering the two items of numeric data into a single string control. Such items being separated by a space.

Is there a good reason you want to work this way? Under normal circumstances one would expect to enter the two field values in two separate controls on a form. To do it with a single control simply makes it more awkward to use for the operator and adds more work for you to code.

Almost everything is possible, even what you ask for here, but that doesn't mean everything is a good idea. This is a very long way from a good idea.
Mar 30 '18 #6

Post your reply

Sign in to post your reply or Sign up for a free account.