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

How to set query as recordsource of form in vb

Status
Not open for further replies.

mrbboy

Technical User
Feb 28, 2007
136
US
I have a form, frm_CARReview, that I want the data filtered using a selection in combo box, cbo_Choices in another form frm_Choices. The choices are All, Open and Close. The first filter is to give me the last record in tbl_CARGeneral.

SELECT Last(tbl_CARGeneral.CARID) AS LastOfCARID, tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
FROM tbl_CARGeneral INNER JOIN tbl_Employee ON tbl_CARGeneral.[Initiated By] = tbl_Employee.EmployeeID
GROUP BY tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
HAVING (((tbl_CARGeneral.Status)=[Forms]![frm_Choices]![cbo_Choices]));


The second filter gives me the first record in tbl_CARGeneral.

SELECT First(tbl_CARGeneral.CARID) AS FirstOfCARID, tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
FROM tbl_CARGeneral INNER JOIN tbl_Employee ON tbl_CARGeneral.[Initiated By] = tbl_Employee.EmployeeID
GROUP BY tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
HAVING (((tbl_CARGeneral.Status)=[Forms]![frm_Choices]![cbo_Choices]));

The third filter gives me everything in tbl_CARgeneral.

SELECT tbl_CARGeneral.CARID, tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
FROM tbl_CARGeneral INNER JOIN tbl_Employee ON tbl_CARGeneral.[Initiated By] = tbl_Employee.EmployeeID
GROUP BY tbl_CARGeneral.CARID, tbl_Employee.Employee, tbl_CARGeneral.[Date Initiated], tbl_CARGeneral.Status
HAVING (((tbl_CARGeneral.Status)=[Forms]![frm_Choices]![cbo_Choices]));

Thanks for the help.
 
How do I assign these three different queries as the recordsource of the form?
 
In the form's OnLoad event, you can put

Code:
Select Case Form![frm_Choices]!cbo_Choices
Case "ALL"
   Me.Recordsource = "BLAH1"

Case "OPEN"
   Me.recordsource = "BLAH2"

Case "Closed"
   Me.Recordsource = "BLAH3"

End Select


Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top