简体   繁体   中英

MS Access 2010 Linking count results to individual records

I have written a sql query in ms access 2010 which counts monthly enquiries, with the user inputting the month parameter. It returns 2 columns - the month name and the total monthly enquiries for that month.

SELECT Format([DateOfEnquiry],"mmmm") AS [Month], Count(T_Enquiry.[DateOfEnquiry]) AS TotalMonthlyEnquiries
FROM T_Enquiry
GROUP BY Format([DateOfEnquiry],"mmmm")
HAVING (((Format([DateOfEnquiry],"mmmm"))=[Enter full name of month]));

After running this query, is it then possible to click on the value in the TotalMonthlyEnquiries column and have Access run another query which returns the individual records corresponding to that value (fields like FamilyName , FirstName , Email , Phone , DateOfEnquiry from T_Enquiry )? If it is possible, how would this be achieved in ms access 2010?

Did this in 2007 but should be very similar if not the same. Create a query with as yours above (Query1 in this example). Create another query which grabs the detail data you want from T_Enquiry (FamilyName, FirstName, Email, Phone, DateOfEnquiry) as Query2.

Create a datasheet form based on Query1 (I've called it frmQuery1 in this example) - I just used the form wizard to save time. Open the form for editing and right-click on the TotalMonthlyEnquiries textbox and go to Properities. On the Format tab, set DisplayAsHyperlink to Always (this will indicate to the user they can click on the link. On the OnClick even on the textbox, enter the following code:

Private Sub TotalMonthlyEnquiries_Click()

    DoCmd.OpenForm "frmQuery2", acFormDS

    Forms!frmQuery2.Filter = "Format([DateOfEnquiry], ""mmmm"") = '" & Me![Month] & "'"
    Forms!frmQuery2.FilterOn = True

End Sub

Save frmQuery1. Create another wizard-based datasheet form off Query2 (the detail data) and save it as frmQuery2.

Now open frmQuery1 - you will be asked to supply a month. When you do and the datasheet comes up, the quanity should be hyperlinked. Click on the hyperlink and frmQuery2 should open up with the data for only the month in question.

Just a simple opening up of another form and passing the value (in this case, month name) from the first form to the second as the filter parameter. There are more complex ways to do this, but this is one of the simplest. Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM