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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select a field for a query from a form

Status
Not open for further replies.

peitzza

Technical User
Apr 13, 2000
80
US
is there any way to select a field name in a combo box(or text box) in a form and query that field?<br><br>i've tried the following:<br><br>SELECT =[forms]![form1]![Text5]<br>FROM table1<br>WHERE ((([table1].[Family])&lt;&gt;&quot;*&quot;));<br><br>-of course this doesn't work does anyone kno wat will?<br>thanx in advance! <p>Peter Heaton<br><a href=mailto:heaton@characterlink.net>heaton@characterlink.net</a><br><a href= it how ever you want</a><br>
 
I think the best way is to make your SQL from code: something like:<br>Suppose you want to change the recordsource of a subform (frmSubform) on a form and cboBox is the combo-box where you set your field:<br><br>sub cboBox_Afterupdate()<br>dim strSQL as string<br>strSQL = &quot;SELECT &quot; & Me![Text5] & &quot;FROM table1 WHERE Family&lt;&gt;'*';&quot;<br><br>me!frmSubform.recordsource = strSQL<br>me!frmSubfrom.Requery<br><br>End sub<br><br>although I do not exactly know what you want to achieve with your where statement:<br>-do you realy have * in the Family field? If not it doesn't mean a lot<br>- I guess you would like to select all the empty fields<br>use: Family Is Not Null<br>-or the empty fields: Family Is Null<br>-or all the Families starting with a: Family Like 'a*'<br>- or all the Families containing an a: Family Like '*a*'<br><br>Hope this helps,<br><br>greetings,<br><br>Dirk<br><br><A HREF="mailto:dirk.news@yucom.be">dirk.news@yucom.be</A><br>
 
thanx dirkg, i think you got me on the right track, but is there a way to reference the text/or combo box in the SQL of a query without code? <p>Peter Heaton<br><a href=mailto:heaton@characterlink.net>heaton@characterlink.net</a><br><a href= it how ever you want</a><br>
 
Yes in the QBE grid just right click on field row. Then click build. Select the field on the form you want to reference. You want to add another field to the form that you can set criteria also.<br>the SQL will look like:<br><br>SELECT [Forms]![Form1]![Combo0] AS type<br>FROM EXTTypeTBL<br>WHERE ((([Forms]![Form1]![Combo0])=[Forms]![Form1]![Text2]));<br>&nbsp;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top