MS Access: Filter/Search records in a form using main form and subform criteria from user input - ms-access

I'm currently working on a database which is rather complex, at least for my ability level. Essentially it is a database of projects, structures and contacts. Within these structures there are sub structures each with unique attributes.
Projects, structures and contacts are joined together in one main control form with a tabbed pane. And within these panes are the forms which have multiple subforms. I am trying to write a search function which I can place on each form that will allow the user to select multiple criteria to filter results. However, some of the criteria or on the forms and other criteria are drawn from multiple subforms and to top it off some fields in the subforms have multiple entries. I understand that this may not sound like very sound database design, but I've been told to adhere to a specific structure and layout which I am not skilled enough to work through.
I've been looking through allen browne's website regarding search criteria, but that is only one a single form. I've attempted to piece together the Subquery tutorial page as well, but to no avail. Essentially, I'm wondering if it is at all possible to filter information say.. the type of structure which is on the main form and then for example.. a range of numbers such as length which exists in a subform and an object proximity which exists in another subform, and have it so that the main form only displays records which fulfill that combination of criteria from the subforms and main form.
My apologies if this is vague, and if it'll help I can post up the general framework I have for my database thus far. Thank you for any assistance you can provide.
EDIT--- Added screenshots for more information
I can't post images since my rep is below 10 but hopefully I can include links
http://img829.imageshack.us/img829/1594/99258898.png
http://img40.imageshack.us/img40/2186/27578829.png
It's difficult to see here, but within the combo boxes some are multi-valued lists. And the combo box on the first image to the right, is switched based on the selection of Type from the upper left combo box, which has different attributes. Ideally I'd like to be able to search through primary forms and subforms. and result in records which only fulfill all the user inputted data. Right now I've tried using filters, one for each criteria, but all that does is blank out information in the subforms which doesn't correspond to the filter criteria.

Do you have any screenshots you could possibly post?
This sounds to me like a larger design issue, perhaps mostly in your UI but possibly in your table structure as well. One my own principles I try to follow is to limit how many things a single screen/form does or shows. What your describing sounds quite confusing to me and I think the average user could easily be overwhelmed by it.
Normally subforms are the result of a main form. That is, they contain child records and are linked to records in the main form via the child records foreign key and the main forms primary key. It isn't that there aren't other ways to design your forms but this is considered "normal" or "standard" design. Your description indicates that filtering the main form is determine by filters set on the subforms. I guess I can't think of any problem that could possibly need solving through something as confusing and clumsy as this. I leave the possibility open that I haven't encountered something as difficult or complex as you're dealing with.
I think you may have some difficulty getting better help here as your question is really better suited to a discussion forum such as UtterAccess.com. You may consider posting a copy of your database on such a site so the users can review your design and possibly recommend a more solid and standard approach.
Edit1:
1) Based on your screenshots, I think you're trying to do too many things in one form. I would normally take each of your top tabs (Projects, Structures, Companies, Contacts) and make each of those their own form. Access 2007 and 2010 allow you to use a tabbed interface natively and I can't think of any real benefit to using the tabbed container control to develop your own tabbed interface.
2) It's my opinion that searches should normally be performed in a single main form that has a single listbox, datasheet view subform, or continuous forms subform. Whichever of these three you choose is not overly important. After performing the search, the user should be able to click in the resulting records in the listbox or subform to select that record and move to it on a details view form similar to what you've already built here. It might take several different search screens to allow your users to search all of the different ways you'd like them to. For example, you might build a screen to search projects, one to search structures, another to search contacts, and a fourth one to search companies. It should be possible to combine some of these in a query and allow the user to search by more than one criteria but it can get confusing if you try to allow them to search too many fields at once, especially if the fields they are searching are in separate tables. For example, if you build a query that shows all projects, structures, and companies together and use this as the recordsource for a datasheet subform, this could allow users to search by project, structure, or company. However, if a project has 10 structures that project will be listed 10 times in the query/form which could confuse users if they are thinking about searching by project. If they are instead searching by structure, it will make perfect sense to them that there are 10 entries for the same project since they'll see 10 different structures.
My basic recommendation is, be careful about trying to build too many functions into a single form. There are some types of tasks or sets of data that do require complex forms with multiple subforms and lots of controls, but in general you want to try to avoid this. It's better to build each form with a very focused task and just simply build more forms to accomplish all of the necessary tasks. Of course, you can take this approach too far as well but you do really need to try to minimize complexity to save yourself from headaches in the future.
As far as filtering based on multiple criteria, I'll see if I can find any good examples or maybe put one together and make it available. It isn't so difficult but it is a multi-step process to build and experience has led me to a general design that I'm happy with and that works almost flawlessly in every possible situation.
Edit2:
Here's how you can create a multi-field filter/search.
1) Build your query. Include all tables and fields which need to viewed by the user or searched on by the user. You can include fields here that will be searched on but not viewable by the user, although that could be confusing to the user. Save your query and give it an appropriate name. Be sure to include your id/primary key fields since those will be needed in step number 4.
2) Now Highlight your query in the navigation pane, go to the top menu and choose Create > More Forms > Datasheet (I'm using Access 2007). Allow access to create and show you a datasheet form which we will use as a subform. Save this and give it an appropriate name like subformProjectSearch of fsubProjectSearch.
3) Get the design view for the new form you just created. Change the properties to disallow additions, deletions, and edits unless you'd really like to allow any of these operations. In general, I don't allow any data entry in these kinds of search forms unless I have it well planned out and tested.
4) Go to the code for this form and add code to popup relevant detail forms on double click. For example, in the projectid or project name field, allow your user to double click to bring up the project details form. Add double click routines to any other textbox where the user might want to pop up a structure, company or contact, assuming you've chosen to include one or more of those in your query. You're code will look something like DoCmd.OpenForm "ProjectDetails", , , "ProjectID = " & Me!ProjectID Now save your form again and close it.
5) Now create a new blank form and add your first form as a subform. Leave room at the top to add controls for filtering. This form does not need to have any recordsource set.
Diversion: I usually take one of two different approaches to filtering. Number one is to give the user one textbox that they can type into. I think do fuzzy searches in a whole bunch of different fields using the data they've typed in. It's a perfectly awful approach performance wise, especially once the database grows past about 20,000 records. It can also lead to some confusion since too many results will likely come up for a short generic search. If they only type in the letter s and search for it they will likely get almost all records.
The second approach I use is probably more common. Give them a different textbox for every field they are likely to want to search by. You an also make it a checkbox or combobox if that fits the field they are searching on. These will not be bound controls. This allows the user to get fairly specific and it also is most likely to return the exact results they are looking for. As far as the code goes, I don't think that one approach is really much simpler than the other. With either approach that I've listed here you really need to check the type of data they've entered before you put it in your filter statement for certain fields. For example, you wouldn't want to try to filter a date field using their non-date, text input. On this second approach you can possibly eliminate more of this problem by using validation rules, input masks, or by setting the textboxes format property. Combos also help to prohibit incorrect data from being entered.
Yet a third option is somewhat of a hybrid approach. You can create one text box that searches on more than one field but not necessarily on all fields. For example, you might create one textbox that will be used to search on Company, FirstName, or LastName. You can create as many of these textboxes as you need. How the input in these textboxes gets used will be totally determined by you in your VBA code.
6) Now that you've decided which approach you want to take, you can go ahead and add your controls. Give them appropriate names and labels.
7) Now it's time to create the function that will build the filtering statement. Use one of the two ideas I listed below. Make sure you run these when the user presses your search button or on the controls AfterUpdate event.
Private Sub txtSearch_AfterUpadate()
Call FilterSubformOption1
End Sub
Private Sub FilterSubformOption1()
Dim strFilter as String
Dim sSearch as String
sSearch = Replace(Nz(Me.txtSearch, ""), "'", "''")
If sSearch <> "" Then
If IsDate(sSearch) = False Then
strFilter = "(ProjectName LIKE '*" & sSearch & "*' OR "
strFilter = strFilter & "StructureName LIKE '*" & sSearch & "*' OR "
strFilter = strFilter & "CompanyName LIKE '*" & sSearch & "*')"
Else
strFilter = "ProjectDate = #" & CDate(sSearch) & "#"
End If
End If
If strFilter <> "" Then
Me.fsubProjectSearch.Form.Filter = strFilter
Me.fsubProjectSearch.Form.FilterOn = True
Else
Me.fsubProjectSearch.Form.Filter = ""
Me.fsubProjectSearch.Form.FilterOn = False
End If
End Sub
Private Sub FilterSubformOption2()
Dim strFilter as String
If Nz(Me.txtProjectName, "") <> "" Then
strFilter = "ProjectName LIKE '*" & Replace(Me.txtProjectName, "'", "''") & "*' AND "
End If
If Nz(Me.txtStructureName, "") <> "" Then
strFilter = strFilter & "StructureName LIKE '*" & Replace(Me.txtStructureName, "'", "''") & "*' AND "
End If
If Nz(Me.txtCompanyName, "") <> "" Then 'Search on multiple fields from one textbox
strFilter = strFilter & "CompanyName LIKE '*" & Replace(Me.txtCompanyName, "'", "''") & "*' AND "
End If
If IsNull(Me.txtProjectDate) = False Then
If IsDate(Me.txtProjectDate) = True Then
strFilter = strFilter & "ProjectDate = #" & Me.txtProjectDate & "#"
End If
End If
If Right(strFilter, 5) = " AND " THEN strFilter = Left(strFilter, Len(strFilter) - 5)
If strFilter <> "" Then
Me.fsubProjectSearch.Form.Filter = strFilter
Me.fsubProjectSearch.Form.FilterOn = True
Else
Me.fsubProjectSearch.Form.Filter = ""
Me.fsubProjectSearch.Form.FilterOn = False
End If
End Sub
Private Sub FilterSubformOption3()
Dim strFilter as String
If Nz(Me.txtProjectName, "") <> "" Then
strFilter = "ProjectName LIKE '*" & Replace(Me.txtProjectName, "'", "''") & "*' AND "
End If
If Nz(Me.txtStructureName, "") <> "" Then
strFilter = strFilter & "StructureName LIKE '*" & Replace(Me.txtStructureName, "'", "''") & "*' AND "
End If
If Nz(Me.txtName, "") <> "" Then 'Search on multiple fields from one textbox, the "hybrid" solution
strFilter = strFilter & "(CompanyName LIKE '*" & Replace(Me.txtName, "'", "''") & "*' OR "
strFilter = strFilter & "FirstName LIKE '*" & Replace(Me.txtName, "'", "''") & "*' OR "
strFilter = strFitler & "LastName LIKE '*" & Replace(Me.txtName, "'", "''") & "*') AND "
End If
If IsNull(Me.txtProjectDate) = False Then
If IsDate(Me.txtProjectDate) = True Then
strFilter = strFilter & "ProjectDate = #" & Me.txtProjectDate & "#"
End If
End If
If Right(strFilter, 5) = " AND " THEN strFilter = Left(strFilter, Len(strFilter) - 5)
If strFilter <> "" Then
Me.fsubProjectSearch.Form.Filter = strFilter
Me.fsubProjectSearch.Form.FilterOn = True
Else
Me.fsubProjectSearch.Form.Filter = ""
Me.fsubProjectSearch.Form.FilterOn = False
End If
End Sub
And that pretty much completes the multiple criteria filtering solution I typically use.

I create complex query-by-form interfaces for nearly all my Access apps. Why? Because my users want them! There are some screenshots of some older examples on my website, but none really is very clear. The point is that I'm writing SQL on-the-fly, and choosing whether to query particular tables based on whether there are criteria sought for that table.
I can say a lot more about, but it quickly shades into proprietary information. If these look like the direction you want to go, why don't you create a new question with enough information to suggest how it could be done based on these principles.

Related

Access VBA Keyword Search Function on multiple fields

I currently have a simple Access database with forms for the users to fill out based off a queried table.
My goal is to use a search box that can filter results based off a keyword multiple times. My existing code works great for a single search on 1 field. I want to be able to drill down off the first search by searching off another field. After I select my field from combo box and search keyword, my results are displayed. Once I pick another field from the same box and search, the results do not include my 1st filter.
On the form, I already have a combo box with a list of all the fields to choose from. Then next to that is a text box for the user to search off the chosen field list. I have correct VBA code to search off a single field, but I'd like to drill down from there. Basically, I want the ability to search a keyword on a selected field, and then be able to filter those results further by using the same search box again.
Example: On form, select "borrower" from drop down list and type "Smith" in search box, click search button. THEN I'd like to choose another field such as "Issue Category" from the same drop down list and type "late payment", then click search button. Thus, giving me all records containing the borrower Smith where issues exist of late payments.
I've been spending days on this and finally broke down to come here. I need to know what code I'm needing to add that would accomplish my goal of multiple searches without filter resetting. I am hoping you can help. Here is my code (Text35 is the text box and searchlist is the combobox list of field names):
Private Sub Search_Click()
Dim strSearchValue As String
strSearchValue = Me.Text35.Value
Select Case Me.searchlist.Value
Case "Date"
Me.Filter = "[Date] = #" & strSearchValue & "# "
Case "Account number"
Me.Filter = "[Account number] = #' & strSearchValue & '# "
Case "Borrower"
Me.Filter = "[Borrower] LIKE '*" & (Replace(strSearchValue, "'", "''")) & "*'"
Case "Issue Category"
Me.Filter = "[Issue Category] LIKE '*" & (Replace(strSearchValue, "'", "''")) & "*'"
End Select
Me.FilterOn = True
End Sub
I think you would use the OR keyword instead of &

multiple item lookup text box

i have created an access 2010 search box that filters results based on a column within a table and then presents me with the results based on query.
what i am trying to achieve is to be able to put not just one item at a time in the search box but multiple items.
this is for a whole estate of routers that i manage and every day i get a list of routers that need to be status checked so what i am doing now is copying and pasting each router name on the search box and it gives me the status, location and circuit ref but what i want to do i to copy and paste all of the router names in one go and get independent results for each router.
this is the code that i have applied for the filter in the text box:
Where Condition = [Circuit Reference] Like "*" & [Forms]![Query1]! [Text12] & "*"
i could add more text boxes and apply this filters to them but i would still have to copy and paste every router name independently.
i am not an access guru so appologies if this question is too easy to answer but i cant find anything on the web that helps me with my issue.
It sounds like you want multiple wildcard searches on the same field. You can do this by using OR in your SQL query.
Dim strSearchConditions As String
Dim strTerms() As String
Dim strSQL As String
Dim i as Integer
strSearchConditions = ""
strTerms = Split(Me.txtSearch,",") 'Assuming you separate your search terms with a comma
For i = 0 To UBound(strTerms)
If Not strTerms(i) = "" Then
strSearchConditions = " OR [Circuit Reference] Like '*" & strTerms(i) & "*'"
End If
Next i
If Not strSearchConditions = "" Then
strSQL = "Select * FROM tblMyTable WHERE 1=1 AND (" & strSearchConditions & ")"
Else
MsgBox "No search terms!"
End If

MS Access Tab Control Name with Number of Records

I am developing an Access database (using Office 2016) and have several tab controls which I want to display the number of records in the subform/subreport.
After a lot of searching etc I have it working for the subforms using a function which I call in the main forms current event (but in a seperate function so I can also call via a macro when I change the main forms record with a combo box, as it wasn't updating otherwise). The code I am using is:
Function ClientTotals()
Dim i As Integer
i = Form_sbfrm_ClientContacts.Recordset.RecordCount
Form_frm_Clients.ClientTabs.Pages("Contacts").Caption = "Contacts (" & i & ")"
End Function
This works perfectly for me and my tab name becomes "Contacts (No. of records)" but I can't get the syntax right to change this to work for a report, is it possible?
I have tried:
Function ClientTotals()
Dim i As Integer
i = Form_sbfrm_ClientContacts.Recordset.RecordCount
Form_frm_Clients.ClientTabs.Pages("Contacts").Caption = "Contacts (" & i & ")"
Dim j As Integer
j = Report_rpt_CurrentProjects.Recordset.RecordCount ' this line is highlighted with the debugger
Form_frm_Clients.ClientTabs.Pages("Current Projects").Caption = "Current Projects (" & j & ")"
End Function
As well as:
Dim j As Integer
j = rpt_CurrentProjects.Report.Recordset.RecordCount ' this line is highlighted with the debugger
Form_frm_Clients.ClientTabs.Pages("Current Projects").Caption = "Current Projects (" & j & ")"
and various others.
Another question I have is why is the syntax for the form "Form_sbfrm" etc and not using a "!". If I change to "!" it bugs out.
Thanks for your help, KAL
Thanks Delecron,
I think I will stick with the tabs for now as they are giving me exactly what I want, but remember what you have said for when I make future improvements if its a better way of doing it.
EDIT
Using what you have said I changed my VBA to a DCOUNT method:
Dim j As Integer
j = DCount("*", "qry_CurrentProjects", "FK_Project_Client_ID = Forms!Navigation!Navigationsubform.form!Client_ID")
Form_frm_Clients.ClientTabs.Pages("Current Projects").Caption = "Current Projects (" & j & ")"
This means my report tabs are now also working just how I wanted
I was getting in a muddle with the criteria/filter, hense the edit.
If Recordset is an old method I am assuming it would be best to replace my other code with the Dcount method?
Thanks again, KAL
Further EDIT
After doing this I could see that everytime the form was changed there was a slight flicker. Not bad but you could see there was a lot of calculation going on. Therefore I have changed my method to the following, and posted here for anyone looking at this in the future.
In the form footer a textbox with COUNT([Project_ID])
In my function
Dim j As Integer
j = Form_frm_Clients!rpt_CurrentProjects.Report!txt_CurrentProjectsCount.Value
Form_frm_Clients.ClientTabs.Pages("Current Projects").Caption = "Current Projects (" & j & ")"
Now I can see it is working quicker with no flicker.
Recordset if you need to return complex data, if you need one value, a total or a sum, Domain functions are the way to go. Don't overdue them though, having too many on a form or a report can start to bog down usability.
Glad I can help.
Recordset.Recordcount is a legacy feature that only worked in ADP files (Access front end's to a SQL database). Those are no longer supported.
If the report is based on 1 client only and there is no grouping then you can do this:
Click on the detail section and in Events create an event for On Paint. In there set
(Name of Page).Caption = DCount("*", "NAME OF QUERY/TABLE") or
(Name of Page).Caption = DCount("*", "NAME OF QUERY/TABLE", "Filter Expression") (Filter expression optional).
If the report is grouped where it will show a different page per client or date range or any other grouping this will not work since the Caption field is not data bound. You would have to add logic to the Dcount statement above to field by the current filter condition.
For example, say you have a database of 200 clients and you're running one big report on all of them, each page will get its own tab control per client, the syntax would be
(Name of Page).Caption = DCount("*", "ClientContacts, "ClientID = " & ClientID)
The better way to do it especially if you are grouping is get rid of the tab control and use databound controls. You could create a box around the information that would be in the tab page and put a textbox where the tab would go. Create a group header for however you are grouping the data. Create another invisible textbox in the group header and set the controlsource = Count([fieldname]) where fieldname is whatever you are grouping the data by (the inside brackets count).
Then in the textbox you created to simulate the tab, set the controlsource to the name of the invisible textbox.
Let me know if this helps.

MS Access Search Form for Large database

I'm building a database that will be accommodating a large number of records, so I want a search function that is easiest on the server. I am using the following code but I know it isn't sustainable for a larger database. It's looking at the search box and running a query to narrow the search results:
Private Sub SearchFor_Change()
'Create a string (text) variable
Dim vSearchString As String
'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = SearchFor.Text
'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll
SrchText.Value = vSearchString
'Requery the List Box to show the latest results for the text entered in Text Box
'SearchFor
Me.SearchResults.Requery
'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from
'Text Box SearchFor
If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be feeding
'off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor,
'and restores trailing space lost when focus is shifted to the list box
Me.SearchFor = vSearchString
Me.SearchFor.SetFocus
Me.SearchFor.SelStart = Me.SearchFor.SelLength
Exit Sub
End If
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be
'feeding off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus
If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
Ideally I want a form that has several search fields, and one 'find' button that runs the queries to return the results in a list box.
I'm also not sure how to set it up so that when the user double clicks on a selection from the search results, the selected record is opened in a form in edit mode.
Any help would be much appreciated, thanks!
First off, you've asked two questions in one post. I recommend you take out the second question regarding opening the selection in edit mode on double click.
As best as I can understand, you're concerned about the performance of your current code as well as the lack of features or flexibility it offers.
Regarding performance:
Don't use the change method to perform the filter. If you really do want to use the change method, use it only to set a timer interval to something like 500 (ms) and then perform the filter on the Timer event. This was the filter won't occur until after the user has stopped typing for a half second.
Avoid "fuzzy" searches (use of asterisk/percent in text fields). It doesn't look like you're using them now. While fuzzy searches usually make software more user friendly, they make it less user friendly when they cause a significant hit on the performance.
When working with large amounts of data, most performance gains come from carefully restructuring the way your application works, by upgrading to SQL Server, and by upgrading your server and network to better hardware. You can only improve about so much when using a JET/ACE backend database container. SQL Server with ADO and ODBC linked tables both offer some advantages over DAO with JET/ACE. ODBC linked tables offer lazy loading while ADO offers things like disconnected recordsets which can be filtered without an additional call back to the server (there are limitations to this).
As already mentioned above, you might need to carefully rethink how your application works and how it is designed. It's better to try to limit the amount of complicated queries that are needed and the amount of text-based searching that is allowed/required. Use more lookup/reference tables. Instead of storing thinks like categories as text, consider storing them as a Long Number CategoryID instead. Queries on indexed numeric fields usually perform better than queries on text-based fields, especially if you are using LIKE with asterisks in your query.
As far as the rest of your question (flexibility and features), consider creating a procedure that builds a criteria/where statement for you based on the values of multiple controls. In a situation such as yours my code would look something like this (below). Notice that I did use asterisk (fuzzy search) in my Description search/filter. If it performs poorly you'll need to consider taking that out and allowing the user to put their own asterisks in instead.
Private Sub cmdSearch_Click()
Call SetRowSource
End Sub
Private Sub txtSearch_AfterUpdate()
Call SetRowSource
End Sub
Private Sub cboCategoryID_AfterUpdate()
Call SetRowSource
End Sub
Private Sub txtBrand_AfterUpdate()
Call SetRowSource
End Sub
Private Sub SetRowSource()
Dim sSQL as String
sSQL = "SELECT ItemID, Description, Brand FROM tblItems "
sSQL = sSQL & GetWhere
Me.lstSearchResults.RowSource = sSQL
End Sub
Private Function GetWhere() as String
Dim sWhere as String
If Nz(Me.cboCategoryID, 0) <> 0 Then
sWhere = sWhere & "CategoryID = " & Me.cboCategoryID & " AND "
End If
If Nz(Me.txtSearch, "") <> "" Then
sWhere = sWhere & "Description LIKE '*" & Replace(Me.txtSearch, "'", "''") & "*' AND "
End If
If Nz(Me.txtBrand, "") <> "" Then
sWhere = sWhere & "Brand = '" & Replace(Me.txtBrand, "'", "''") & "' AND "
End If
If sWhere <> "" Then
sWhere = Left(sWhere, Len(sWhere)-5)
GetWhere = "WHERE " & sWhere
End If
End Function
I think I might be a little bit odd in the Access community but I generally do not allow my controls to reference other controls. In your case the RowSource in your listbox references the controls of the form it's located on. For a variety of reasons, I prefer to build my SQL statements in VBA code, particularly when they are subject to change/filtering. Another thing you might consider doing is using a Datasheet form instead of a listbox. You can set the form's RecordSource and just apply your WHERE statement to the form's Filter property then. Datasheet forms are more flexible for the user as they can resize columns and do sorting without any help from you the programmer. You can always lock the controls so they can't do any editing. When I use datasheets this way I think use the DoubleClick event to allow them to open the record, which is arguably less user friendly then using the single click on a listbox.

Filtering subform based on multiple criteria in Access

I have a form with 2 checkboxes and 2 comboboxes, and a subform to display the corresponding results.
Can can filter my subform by one of the comboboxes by using :-
Dim LSQL
LSQL = "select * from Queries"
LSQL = LSQL & " where RaisedBy = '" & cboRaisedBy & "'"
Form_frmMainSub.RecordSource = LSQL
but what would be the best approach for enabling a filter on all 4 critieria?
What would be best depends very much on the data to be filtered and the link fields. I generally like to use link child and master fields for filtering subforms, because it works very well with no code at all, but it may not suit you. You can set the link fields to the name of controls as well as to the names of fields. You can also consider a mixture of link child and master fields and the filter property. Updating the sql also works, but it can get tedious, and can interfere too much user-applied filters.