gordonmann
asked on
Wildcard Character in a combo Seach Box
I am trying to use a combo box to find specifc strings in a text field. For example I amy be looking for an HP 980 Printer but the item could be HP 980 or Hewlet-PAckard 980 or 980 Deskjet. I want the combo box to be able to find any of these items and list them rather then finding the text as it is typed from left to right.
Line 2 needs edited to incude any predefined criteria
for example
selectquery = selectquery & (quantityinstock > 0) AND ("
or delete it and add the opening "(" to the first line
for example
selectquery = selectquery & (quantityinstock > 0) AND ("
or delete it and add the opening "(" to the first line
Which database?
what table definitions?
Example does in vba
assume table is
tblPrinters
PrinterID
Description
dim sFilter() as string
dim sSearch as string
dim sWhere as string
dim i as integer
sSearch = "HP 980 Printer"
sFilter = split(sSearch, " ")
sWhere = ""
for i = 0 to ubound(sFilter)
if sWhere <> "" then sWhere = sWhere & " OR "
swhere = swhere & "Description LIKE '*" & sFilter(i) & "*' "
next i
cboPrinters.RowSource = "SELECT PrinterID, Description FROM tblPrinters WHERE " & sWhere
what table definitions?
Example does in vba
assume table is
tblPrinters
PrinterID
Description
dim sFilter() as string
dim sSearch as string
dim sWhere as string
dim i as integer
sSearch = "HP 980 Printer"
sFilter = split(sSearch, " ")
sWhere = ""
for i = 0 to ubound(sFilter)
if sWhere <> "" then sWhere = sWhere & " OR "
swhere = swhere & "Description LIKE '*" & sFilter(i) & "*' "
next i
cboPrinters.RowSource = "SELECT PrinterID, Description FROM tblPrinters WHERE " & sWhere
Note, the approach is similar to llessurt in that we both use SPLIT and we have both made assumptions on the tables
I have just given u the VBA alternative to work with MS Access
llessurt, pls do not think I am copying, I know VBA quite well and would of used split anyway as this is the only way to break up a delimited string. My intention was just to give the VBA alternative.
If u tell use what DB/Language and perhaps your printer table definition, that would help us to give u a more correct solution
I have just given u the VBA alternative to work with MS Access
llessurt, pls do not think I am copying, I know VBA quite well and would of used split anyway as this is the only way to break up a delimited string. My intention was just to give the VBA alternative.
If u tell use what DB/Language and perhaps your printer table definition, that would help us to give u a more correct solution
ASKER
I am finally getting back to this - sorry for the delay.
table = tInventory
Combo Box = cboItemDesc
Bound Column in Combo = InventoryId
Only Search Field = txtItemDesc
I think I understand both approaches but I have to admit rockiroads seems to make more sense to me. However, where do you put all the other code not in the combo box Row Source? I tried to put it all there and I really did not like it at all.
table = tInventory
Combo Box = cboItemDesc
Bound Column in Combo = InventoryId
Only Search Field = txtItemDesc
I think I understand both approaches but I have to admit rockiroads seems to make more sense to me. However, where do you put all the other code not in the combo box Row Source? I tried to put it all there and I really did not like it at all.
Ok, how do u want this approached?
At the moment, we set a string called "sSearch"
Then based on what that is, the combo printer list has its rowsource modified accordinly
So I guess you can modify it to use txtItemDesc
Say u have a button called cmdFind, u use this to load the printers
private sub cmdFind_Click
dim sFilter() as string
dim sSearch as string
dim sWhere as string
dim i as integer
If IsNull(me.txtItemDesc)=Tru e then
msgbox "No search string specified"
exit sub
End if
sSearch = txtItemDesc
sFilter = split(sSearch, " ")
sWhere = ""
for i = 0 to ubound(sFilter)
if sWhere <> "" then sWhere = sWhere & " OR "
swhere = swhere & "Description LIKE '*" & sFilter(i) & "*' "
next i
cboItemDesc.RowSource = "SELECT InventoryID, Description FROM tblInventory WHERE " & sWhere
end sub
What do u mean by
"where do you put all the other code not in the combo box Row Source"
At the moment, we set a string called "sSearch"
Then based on what that is, the combo printer list has its rowsource modified accordinly
So I guess you can modify it to use txtItemDesc
Say u have a button called cmdFind, u use this to load the printers
private sub cmdFind_Click
dim sFilter() as string
dim sSearch as string
dim sWhere as string
dim i as integer
If IsNull(me.txtItemDesc)=Tru
msgbox "No search string specified"
exit sub
End if
sSearch = txtItemDesc
sFilter = split(sSearch, " ")
sWhere = ""
for i = 0 to ubound(sFilter)
if sWhere <> "" then sWhere = sWhere & " OR "
swhere = swhere & "Description LIKE '*" & sFilter(i) & "*' "
next i
cboItemDesc.RowSource = "SELECT InventoryID, Description FROM tblInventory WHERE " & sWhere
end sub
What do u mean by
"where do you put all the other code not in the combo box Row Source"
ASKER
Noiw I am getting confused. I am looking to use this in a combo/list box and your appear to be talking about a command button. This seems like two items. Are you saying I need a text box AND command button that will then populate the list box. (Simmiliar to IIF)
ASKER
After looking at this further I understand what you are suggesting. However, my goal (although it may be unacheivable) is to type into the combo box (like any other search) but have it search for the string anywhere in the text.
I full understand how to do what you suggest.
I full understand how to do what you suggest.
It would be easier to do thru a prompt (txtbox/cmdbtn for example)
My understanding was you wanted the combo filtered, but obviously not.
What you are saying is enter any partial text and try find it in the combo. That might be tricky.
u can type letters in but it finds based on first letter only
My understanding was you wanted the combo filtered, but obviously not.
What you are saying is enter any partial text and try find it in the combo. That might be tricky.
u can type letters in but it finds based on first letter only
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am going to try a command button to open a search form in Modal mode that will hopefully take the vaule back to the correct line in the details part of the form. It appears a combo box is just too difficult
ASKER
Even though I did not choose to persue either of the offered suggestions it is only fair to reward the efforts. Thank you to bioth. Ultimately it was not feasible to put the effort in so I use a seperate modal form to "carry" he value back.
selectquery = "SELECT printermodel, printermake, printerdescription FROM printers WHERE "
selectquery = selectquery & " AND ("
arr = SPLIT(searchstring, " ")
FOR i=0 to UBOUND(arr)
selectquery = selectquery & "((printermodel LIKE '%" & arr(i) & "%') OR (printermake LIKE '%" & arr(i) & "%') OR (printerdescription LIKE '%" & arr(i) & "%')) AND "
NEXT
selectquery = LEFT(selectquery, LEN(selectquery) - 5)
selectquery = selectquery & ")"
rs.OPEN selectquery
DO WHILE NOT rs.EOF
response.write "<option>" & rs("printermodel") & "</option>"
rs.moveNext
LOOP