doing a search using a combo box

P

Pete Montero

Hi what I need to do is this. I am have a database, and I
want to get information from that database into a report
so I made a combo box, I want to get information of a
part number, just by typing part of that number, not the
whole number, what is doing right now is that if I type
the beginning of a number it shows me the whole
partnumber that starts with the same number I typed in,
but I want to know if there is a way to type middle
section of a part number, and still get the information I
want for that partnumber? I really appreciate your help.
 
T

Tim Ferguson

but I want to know if there is a way to type middle
section of a part number, and still get the information I
want for that partnumber?

You could use a separate textbox [txtPattern] and a listbox
[lisSearchResult]: set the rowsource for lisSearchResult to

SELECT PartNumber FROM Parts
WHERE PartNumber LIKE "*" & Forms!ThisForm!txtPattern & "*"
ORDER BY PartNumber

and use the txtPattern_Change event to call

if isnull(txtPattern) Then
' do nothing

elseif len(txtPattern) < 5 then
' do nothing if it's only a short item

else
lisSearchResult.Requery

end if

but don't expect fantastic response times, especially if the network
connection is a bit slow.

Hope that helps


Tim F
 
M

MDW

To get what you want, you may not need a combo box. Try
using an unbound text box instead. Then put the following
code behind the Click() event of a button

txtPartNumber.SetFocus
If txtPartNumber.Text <> "" Then
strWhere = "[PartNumber] LIKE '*" & txtPartNumber.Text
& "*'"

stDocName = "Your Report Name Goes Here"
DoCmd.OpenReport stDocName, acPreview, , strWhere

End If

Thus, if you typed in "PIZZA" in the box, the report could
potentially return any of the following:

PIZZAPART1
PIZZAPART2
MYPIZZA
MYPIZZAPART
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top