|
|
Question : Doing "Like" searches in subform from Textbox
|
|
Access 2003 What I have: Form: "frmSearch" bound to table called..."tblSearch" texbox: "Text1" - bound to "fldLookUpNumber" textbox: "Text13" - unbound...stores the value from "Text1" Subform: name = "sapdatasearch subform" Linkchild fields "MFRNUM" LinkMaster fields "Text13" Recordsource for "sapdatasearch subform" (see below)
What is happening now: As I type a value into Text1.. it fires off the change event which then changes the subform contents to display contents as I type them.. Private Sub Text1_Change() Me![Text13] = Me![Text1].Text End Sub
i.e. So if I type "1" all the results for "1" show up in the subform. if I type another character(alpha or numeric) say..."1B" all the reuslts for "1B" show up in the subform.
WHAT I NEED: I would like to do a "StartsWith" or I guess a "like" statement... i.e. So when I type in a "1" it brings me back data in the suform with anything that starts with a "1" instead of just "Exact Matches"
Thanks fordraiders
Code Snippet:
1:
|
SELECT SapData.MFRNUM, SapData.MFRNAME, SapData.WWGMFRNUM, SapData.WWGMFRNAME, SapData.WWGDESC, SapData.ITEM, SapData.COMMENTS, SapData.REDBOOKNUM, SapData.XREF, SapData.SPIN, SapData.RICHTEXT, SapAltData.ALT1, SapAltData.ALT1SPIN, SapAltData.ALT1DESC, SapAltData.ALT1DESC2, SapAltData.ALT2, SapAltData.ALT2XREFTYPE, SapAltData.ALT2COMMENTS, SapAltData.ALT2SPIN, SapAltData.ALT2MFGNAME, SapAltData.ALT2MFRNUM, SapAltData.ALT2DESC, SapAltData.ALT2DESC2, SapAltData.ALT2BOOKPAGE, SapAltData.ALT3, SapAltData.ALT3XREFTYPE, SapAltData.ALT3COMMENTS, SapAltData.ALT3SPIN, SapAltData.ALT3MFGNAME, SapAltData.ALT3MFRNUM, SapAltData.ALT3DESC, SapAltData.ALT3DESC2, SapAltData.ALT3BOOKPAGE FROM (SapData LEFT JOIN SapAltData ON SapData.ITEM=SapAltData.ITEM) LEFT JOIN AlternatesPL ON SapData.ITEM=AlternatesPL.ITEM;
|
Open in New Window
Select All
|
Answer : Doing "Like" searches in subform from Textbox
|
|
You have to clear the linkchild & linkmaster properties, so that the link is not automatic. Set the subform recordsource to the modifed query below (last line added) In the change event you need additional lines:
me.subformcontrolname.Form.requery DoEvents
subformcontrolname is the name of the control on frmsearch which holds the subform. It might be the same as the name of the subform, but not necessarily.
SELECT SapData.MFRNUM, SapData.MFRNAME, SapData.WWGMFRNUM, SapData.WWGMFRNAME, SapData.WWGDESC, SapData.ITEM, SapData.COMMENTS, SapData.REDBOOKNUM, SapData.XREF, SapData.SPIN, SapData.RICHTEXT, SapAltData.ALT1, SapAltData.ALT1SPIN, SapAltData.ALT1DESC, SapAltData.ALT1DESC2, SapAltData.ALT2, SapAltData.ALT2XREFTYPE, SapAltData.ALT2COMMENTS, SapAltData.ALT2SPIN, SapAltData.ALT2MFGNAME, SapAltData.ALT2MFRNUM, SapAltData.ALT2DESC, SapAltData.ALT2DESC2, SapAltData.ALT2BOOKPAGE, SapAltData.ALT3, SapAltData.ALT3XREFTYPE, SapAltData.ALT3COMMENTS, SapAltData.ALT3SPIN, SapAltData.ALT3MFGNAME, SapAltData.ALT3MFRNUM, SapAltData.ALT3DESC, SapAltData.ALT3DESC2, SapAltData.ALT3BOOKPAGE FROM (SapData LEFT JOIN SapAltData ON SapData.ITEM=SapAltData.ITEM) LEFT JOIN AlternatesPL ON SapData.ITEM=AlternatesPL.ITEM Where SapData.MFRNUM like Forms!frmsearch!text13 & "*";
|
|
|
|
|