I have a form called "Search Issues' and a Subform within call "Browse All Issues". Browse All Issues Record source is a table that contains all the data called Issues. I'm trying to create search features within "Search Issues" where I can select multiple criteria from List box and when I click Search Browse all issues filter on the criteria I selected. I currently I the following code:
Private Sub Search_Click()
On erorr GoTo errr
Me.Search.Form.RecordSource = "SELECT * From Browse_All_IssuesSubform " & BuildFilter
Me.Search.Form.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim strWhere As String
strWhere = IIf(Len(Me.AssignedTo & "") <> 0, "([AssignedTo] Like ""*" & Me.AssignedTo & "*"") AND", "") & _
IIf(Len(Me.OpenedBy & "") <> 0, "([OpenedBy] Like ""*" & Me.OpenedBy & "*"") AND", "") & _
IIf(Len(Me.Status & "") <> 0, "([Status] Like ""*" & Me.Status & "*"") AND", "") & _
IIf(Len(Me.Category & "") <> 0, "([Category] Like ""*" & Me.Category & "*"") AND", "") & _
IIf(Len(Me.Priority & "") <> 0, "([Priority] Like ""*" & Me.Priority & "*"") AND", "") & _
IIf(Len(Me.OpenedDateFrom & "") <> 0, "([EnteredOn] >= #" & Format(Me.OpenedDateFrom, "mm/dd/yyyy") & "#) AND", "") & _
IIf(Len(Me.DueDateFrom & "") <> 0, "([EnteredOn] <= #" & Format(Me.DueDateFrom, "mm/dd/yyyy") & "#) AND", "")
If Len(strWhere & "") = 0
Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
Me.Filter = Left(strWhere, Len(strWhere & "") - 4)
Me.FilterOn = True
Me.Requery
End If
BuildFilter = strWhere
End Function
How can I get his to work? When I run the event I get the message "Compile Error" : Method or data member not found.
Please help
If it runs without errors but doesn't filter correctly, you probably got the WHERE clause wrong.
First of all, the word WHERE is completely missing in the SQL string that you're building!
But I don't know if that's all.
Without knowing your database tables (definition and the data inside!), it's very hard for us to find any mistakes in your query.
So you should try to find out by yourself, step by step:
In the Search_Click() sub, output the final SQL string to the Immediate Window:
Debug.Print "SELECT * From Browse_All_IssuesSubform " & BuildFilter
Create a new Access query, switch to SQL view, copy & paste the SQL string from the Immediate Window. Try to run the query.
Does it return more rows than you expected?
Then there's something missing in the WHERE clause. Look at the rows which you didn't expect to be returned, and think about what needs to be added to the WHERE clause to make them disappear from your result set.
Does it return less rows than you expected (or none at all)?
Then you are filtering too much. Try to delete parts of your WHERE clause, step by step, and each time run the query again until you get all the rows that you want.
This should be enough to point you into the right direction.
If you still aren't able to find the mistake, we need much more information.
Related
I can't seem to find any answers here for my specific problem. Maybe it's because I don't know what I'm looking for...
Anyway, I have an Access form that has about 30 checkboxes for each live facility we have and I need to run a query (which works perfectly) based on what boxes are ticked and a begin and end date which are also on the form.
This is the SQL I have (generated by the Query Wizard) that shows every single facility for every single date.
TRANSFORM Count(tblFilesProcessed.[File Name]) AS [CountOfFile Name]
SELECT tblFilesProcessed.[Fac Alpha], tblFilesProcessed.[File Date], Count(tblFilesProcessed.[File Name]) AS [Total Of File Name]
FROM tblFilesProcessed
GROUP BY tblFilesProcessed.[Fac Alpha], tblFilesProcessed.[File Date]
PIVOT tblFilesProcessed.[File Type];
I need to be able to pick and choose what I want the report to show. Right now it shows Facility01 all the way through Facility30 for dates going back to March. I need to be able to tick a box for Facility04, Facility 15, and Facility 20 for the past week. Or Facility 03, 21, 22, 23, 24.
What you will need to do is to use VBA to look at the controls on the form, and build up a modified SQL statement which you will then set to be the query's .SQL. Something like this:
Private Sub cmdQuery_Click()
On Error GoTo E_Handle
Dim strWhere As String
Dim strSQL1 As String
Dim strSQL2 As String
strSQL1 = "TRANSFORM Count(F.[File Name]) AS [CountOfFile Name] " _
& " SELECT F.[Fac Alpha], F.[File Date], Count(F.[File Name]) AS [Total Of File Name] " _
& " FROM tblFilesProcessed AS F "
strSQL2 = " GROUP BY F.[Fac Alpha], F.[File Date] " _
& " PIVOT F.[File Type];"
If Me!chkFac1 = True Then strWhere = strWhere & "'Fac1',"
If Me!chkFac2 = True Then strWhere = strWhere & "'Fac2',"
If Len(strWhere) > 0 Then
strWhere = " AND F.[Fac Alpha] IN(" & Left(strWhere, Len(strWhere) - 1) & ") "
End If
If IsDate(Me!txtFrom) Then
strWhere = strWhere & " AND F.[File Date]>=" & Format(Me!txtFrom, "\#mm\/dd\/yyyy\#")
End If
If IsDate(Me!txtTo) Then
strWhere = strWhere & " AND F.[File Date]<=" & Format(Me!txtTo, "\#mm\/dd\/yyyy\#")
End If
If Left(strWhere, 4) = " AND" Then
strWhere = " WHERE " & Mid(strWhere, 5)
End If
CurrentDb.QueryDefs("qryFilesProcessed").SQL = strSQL1 & strWhere & strSQL2
sExit:
On Error Resume Next
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & vbCrLf & "frmFilesProcessed!cmdQuery_Click", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
I would suggest that rather than using 30 checkboxes, a multi-select list box would be better, as it allows for future proofing - indeed, you could set its .RowSource to be the list of unique Facility values from the table.
I've looked at a bunch of other posts, an nothing seems to get it. This damned Access nomenclature always throws me.
I've got a main form, with a subform. I want to be able to enter a string into a field on the main form, and have the subform filtered as follows:
[Title on Eligibility List] like ""*" & frmNewGeneralclassification_fill_in.!txtsearchstring & "*""
This is not a "link master and child" situation. It's doing a LIKE match.
I've tried
me!frmNewGeneralclassification_fill_in.form.filter = "[Title on Eligibility List] like '*" & me!txtSearchString & "*'"
and
me.frmNewGeneralclassification_fill_in.form.filter = "[Title on Eligibility List] like '*" & me!txtSearchString & "*'"
(Filter is not an Autosense option, but if I type it in anyway, it capitalizes it.)
and I get "object required" error message.
One of those SHOULD work, but they're not.
and
frmJob_Title_Lookup.Form.RecordSource = "SELECT [Job Title to New Classification].[Title on Eligibility list], [Job Title to New Classification].Employer, [Job Title to New Classification].[New Classification in EE], [Job Title to New Classification].[New General Classification] FROM [Job Title to New Classification] WHERE ((([Job Title to New Classification].[New Classification in EE]) Is Not Null) AND (([Job Title to New Classification].[New General Classification]) Is Not Null)) and ([Title on Elibibility List] like '*" & frmNewGeneralclassification_fill_in.txtSearchString & "*'"
frmJob_Title_Lookup.Form.Requery
and I get "Object Required" error message.
Any pointers?
I agree that referencing subforms is really confusing in Access. In this case, try not using 'me' and just fully reference what you need (and remember to turn on your filter):
Screenshot of my form with subform
Private Sub txtSearch_AfterUpdate()
Dim strWhere As String
strWhere = ""
If Not IsNull(Me.txtSearch) Then
strWhere = strWhere & " ([ItemCode] like '*" & Me.txtSearch & "*' OR "
strWhere = strWhere & " [ItemDescription] like '*" & Me.txtSearch & "*') AND "
End If
'remove final AND
If strWhere <> "" Then
strWhere = Left(strWhere, Len(strWhere) - 5)
Forms!frmItemList.frmItemListItemsSF.Form.Filter = strWhere
Forms!frmItemList.frmItemListItemsSF.Form.FilterOn = True
Else
strWhere = "1=1" 'this is always true and forces the filter to clear
Forms!frmItemList.frmItemListItemsSF.Form.Filter = strWhere
Forms!frmItemList.frmItemListItemsSF.Form.FilterOn = True
End If
End Sub
I inherited the database from the guy who left, and have been trying to run maintenance and add functionality as required. I should say that when I stared this job 3 weeks ago, I had absolutely no coding experience, but have picked up things here and there. On to the problem:
The main form has a table nested in there, and the filters were basically set up to filter out and play with the data in the table. I'll try and attach a picture on imugr and add the link (EDIT:http://imgur.com/nHUsCdX)
There are a number of filters and search boxes on the left side. This includes:
A text search box (search through Column A)
A Date search box
Group Filter - searches in Group column, and filters out based on chosen value.
Trending - a filter that basically fills up the Date Search Box (2) with pre-set dates for earnings quarters.
Region Filter - works the same way as Group Filter (3), except search in the region column.
The following lines of code more or less governs these filters and search boxes, i'll post it in its entirety.
Private Sub frmFieldPresets_AfterUpdate()
Dim fieldPreset As String
Select Case Me.frmFieldPresets
Case 1
fieldPreset = "Audit"
DoCmd.OpenForm "frm_Fields"
Call Forms.frm_Fields.cmd_De_SelectAllFields_Click
Forms.frm_Fields.chk_EN.Value = True
Forms.frm_Fields.chk_BLI.Value = True
Forms.frm_Fields.chk_AN.Value = True
Forms.frm_Fields.chk_EDD.Value = True
Forms.frm_Fields.chk_GIIC.Value = True
Forms.frm_Fields.chk_NILGIC.Value = True
Forms.frm_Fields.chk_RDTTO.Value = True
Forms.frm_Fields.chk_ESB.Value = True
Call Forms.frm_Fields.refreshFields
DoCmd.Close acForm, "frm_Fields"
Case 2
fieldPreset = "CMRM"
DoCmd.OpenForm "frm_Fields"
Call Forms.frm_Fields.cmd_De_SelectAllFields_Click
Forms.frm_Fields.chk_BLI.Value = True
Forms.frm_Fields.chk_AN.Value = True
Forms.frm_Fields.chk_OID.Value = True
Forms.frm_Fields.chk_EN.Value = True
Forms.frm_Fields.chk_GIIC.Value = True
Forms.frm_Fields.chk_NILGIC.Value = True
Forms.frm_Fields.chk_RDTTO.Value = True
Forms.frm_Fields.chk_EDD.Value = True
Call Forms.frm_Fields.refreshFields
DoCmd.Close acForm, "frm_Fields"
Case 3
fieldPreset = "Finance"
DoCmd.OpenForm "frm_Fields"
Call Forms.frm_Fields.cmd_De_SelectAllFields_Click
Forms.frm_Fields.chk_EN.Value = True
Forms.frm_Fields.chk_RDTTO.Value = True
Forms.frm_Fields.chk_BLI.Value = True
Forms.frm_Fields.chk_GIIC.Value = True
Forms.frm_Fields.chk_NILGIC.Value = True
Call Forms.frm_Fields.refreshFields
DoCmd.Close acForm, "frm_Fields"
Case 4
fieldPreset = "TBM"
DoCmd.OpenForm "frm_Fields"
Call Forms.frm_Fields.cmd_De_SelectAllFields_Click
Forms.frm_Fields.chk_EN.Value = True
Forms.frm_Fields.chk_BLI.Value = True
Forms.frm_Fields.chk_AN.Value = True
Forms.frm_Fields.chk_RDTTO.Value = True
Forms.frm_Fields.chk_GIIC.Value = True
Forms.frm_Fields.chk_NILGIC.Value = True
Forms.frm_Fields.chk_EDD.Value = True
Call Forms.frm_Fields.refreshFields
DoCmd.Close acForm, "frm_Fields"
Exit Sub
End Select
End Sub
Private Sub frmRegions_AfterUpdate()
Call refresh_Filters
End Sub
Private Function regionselection()
Select Case Me.frmRegions
Case 1
regionselection = "Canada"
Case 2
regionselection = "USA"
Case 3
regionselection = "Singapore"
Case 4
regionselection = "Europe & Asia Pacific"
Case 5
regionselection = "Global"
End Select
End Function
Private Sub frmTrendingQuarters_AfterUpdate()
Dim fieldPreset As String
Select Case Me.frmTrendingQuarters
Case 1
txtDate1.Value = "11/1/2014"
txtDate2.Value = "1/31/2015"
fieldPreset = "Q1"
Case 2
txtDate1.Value = "2/1/2015"
txtDate2.Value = "4/30/2015"
fieldPreset = "Q2"
Case 3
txtDate1.Value = "5/1/2015"
txtDate2.Value = "7/31/2015"
fieldPreset = "Q3"
Case 4
txtDate1.Value = "8/1/2015"
txtDate2.Value = "10/30/2015"
fieldPreset = "Q4"
Exit Sub
End Select
DoCmd.OpenForm "frm_Fields"
Call Forms.frm_Fields.cmd_De_SelectAllFields_Click
Forms.frm_Fields.chk_OID.Value = True
Forms.frm_Fields.chk_EN.Value = True
Forms.frm_Fields.chk_FWCO.Value = True
Forms.frm_Fields.chk_Reg.Value = True
Forms.frm_Fields.chk_RC.Value = True
Forms.frm_Fields.chk_Rem1.Value = True
Forms.frm_Fields.chk_Rem2.Value = True
Forms.frm_Fields.chk_RDTTO.Value = True
Call Forms.frm_Fields.refreshFields
DoCmd.Close acForm, "frm_Fields"
Call refresh_Filters
End Sub
Private Sub txtDate1_AfterUpdate()
Call refresh_Filters
End Sub
Private Sub txtDate2_AfterUpdate()
Call refresh_Filters
End Sub
Private Sub txtSearch_AfterUpdate()
Call refresh_Filters
End Sub
Private Sub refresh_Filters()
Dim searchFilter, dateFilter, allFilter As String
Dim searchString, date1String, date2String As String
Me.Refresh
If IsNull(Me.txtSearch) Then
searchString = "*"
Else
searchString = Me.txtSearch
End If
If IsNull(Me.txtDate1) Then
date1String = "1/1/2000"
Else
date1String = Me.txtDate1
End If
If IsNull(Me.txtDate2) Then
date2String = "1/1/2020"
Else
date2String = Me.txtDate2
End If
searchFilter = "(" & "[Event Name] Like '*" & searchString & "*'" & ")"
regionFilter = "(" & "[Region] Like '*" & regionselection & "*'" & ")"
dateFilter = "(" & "[OpERA Create Date] Between " & "#" & date1String & "#" & " AND " & "#" & date2String & "#" & ")"
allFilter = searchFilter & " And " & dateFilter & " And " & regionFilter
Me.frm_ORE_All.Form.Filter = allFilter
Me.frm_ORE_All.Form.FilterOn = True
End Sub
Now the part I need help with is the last few lines of code. At some point, I was told the parameters for textSearch, which was only looking in one column (Event Name), needed to be expanded to include additional columns. So the search would expand to look through more columns. So I changed the code for searchFilter, and added more columns to it.
This is the UPDATED code, the last few lines.
'searchFilter = "(" & "[Event Name] Like '*" & searchString & "*'" & ")"
searchFilter = "(" & "[Event Name] Like '*" & searchString & "*'" & ") OR (" & "[Event Submitted By] Like '*" & searchString & "*'" & ") OR (" & "[Organizational Business Unit] Like '*" & searchString & "*'" & ") OR (" & "[Business Line Impacted] Like '*" & searchString & "*'" & ") OR (" & "[Attester Name] Like '*" & searchString & "*'" & ") OR (" & "[Comments] Like '*" & searchString & "*'" & ") OR (" & "[Function Where Cause Occurred] Like '*" & searchString & "*'" & ") OR (" & "[Root Cause] Like '*" & searchString & "*'" & ") OR (" & "[Remedy 1] Like '*" & searchString & "*'" & ") OR (" & "[Remedy 2] Like '*" & searchString & "*'" & ")"
regionFilter = "(" & "[Region] Like '*" & regionselection & "*'" & ")"
dateFilter = "(" & "[OpERA Create Date] Between " & "#" & date1String & "#" & " AND " & "#" & date2String & "#" & ")"
allFilter = searchFilter & " And " & dateFilter & " And " & regionFilter
Me.frm_ORE_All.Form.Filter = allFilter
Me.frm_ORE_All.Form.FilterOn = True
End Sub
Once I slot in this new line of code for searchFilter, and decommission the original one, it works perfectly. EXCEPT the other filters stop working for whatever reason. So while GroupFilters still work, Trending and RegionFilter stop working altogether.
If I switch back in the original line of code, and decommission the new one, everything starts working fine again (except the fact that the textboxsearch goes back to searching through one column only).
I'm sure it's just inefficiency in my code, or something glaringly obvious that you'll spot when I don't. Any tips?
This is about operator precedence and how the computer combines your various Or and And statements. Try putting your new searchFilter inside a set of brackets. So,
searchFilter = "((" & "[Event Name] ... [Remedy 2] Like '*" & searchString & "*'" & "))"
This will make sure that your new tests get treated as a single unit with the result of that unit then added to the other tests using the And operator.
A filter on a form is essentially the WHERE clause of a SQL statement.
The problem is that you are missing parentheses in your search string SQL.
The code you are running is this:
Filter = ([Event Name] Like '*SEARCH*')
OR ([Event Submitted By] Like '*SEARCH*')
OR ([Organizational Business Unit] Like '*SEARCH*')
OR ([Business Line Impacted] Like '*SEARCH*')
...
OR ([Remedy 2] Like '*SEARCH*')
AND ([Region] Like '*REGIONSEARCH*')
AND ([OpERA Create Date] Between #DATE1# AND #DATE2#)
What you intend to do is have all of the "OR" statements determined together and then also have the AND statements, but what the code is actually doing is this:
Filter = ([Event Name] Like '*SEARCH*')
OR ([Event Submitted By] Like '*SEARCH*')
OR ([Organizational Business Unit] Like '*SEARCH*')
OR ([Business Line Impacted] Like '*SEARCH*')
...
OR **(** ([Remedy 2] Like '*SEARCH*')
AND ([Region] Like '*REGIONSEARCH*')
AND ([OpERA Create Date] Between #DATE1# AND #DATE2#) **)**
Add the parentheses to the search string to get the appropriate filter:
Filter = **(** ([Event Name] Like '*SEARCH*')
OR ([Event Submitted By] Like '*SEARCH*')
OR ([Organizational Business Unit] Like '*SEARCH*')
OR ([Business Line Impacted] Like '*SEARCH*')
...
OR ([Remedy 2] Like '*SEARCH*') **)**
AND ([Region] Like '*REGIONSEARCH*')
AND ([OpERA Create Date] Between #DATE1# AND #DATE2#)
Surround the search clause in parentheses and this should fix the problem.
I'm trying to update records in my form. It's a restaurant reservation system. Given the Table #, the form can let the user input the Customer ID of the person reserving, the reservation time and date. But when I click on the "update" button in my form, a text box will pop up with this:
And whatever I put in it, the runtime error "too few parameters. expected 1." pops up. Sometimes a "Reserved Error" will pop up. Could someone help me? It's the last step before I could finally finish this project.
This is my code for updating the record:
Private Sub Command8_Click()
On Error GoTo errHandling
Dim strSQL As String
strSQL = "UPDATE tblReserve SET CustomerID = " & """" & Me.txtCustID & """" & _
", ResDate = " & """" & Me.txtResDate & """" & ", ResTime = " & """" & Me.txtTime & """" & " WHERE TableNum =" & Me.TableNum
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.Close
Exit Sub
errHandling:
MsgBox Err.Description
End Sub
Screenshot of VBA editor with Debug.Print strSQL
As revealed in our [chat][1], the essence of the problem was that [TableNum] is a text field and therefore its value had to be enclosed in quotes:
"... WHERE TableNum = '" & Me.TableNum & "'"
[1]: https://chat.stackoverflow.com/rooms/42746/discussion-between-nutellafella-and-gord-thompson)
Try something like this
strSQL = "UPDATE tblReserve SET CustomerID = " & Me.txtCustID & _
", ResDate = " & "'" & Me.txtResDate & "'" & ", ResTime = " & "'" & Me.txtTime & "'" & " WHERE TableNum =" & Me.TableNum
I am not sure why you have 2 sets of double quotes inside double quotes, I think what you were looking for is single quotes :)
However, there are much better ways to format sql than this. Also this seems like homework, so study up!
I've created a search tool that has a few issues I can't seem to iron-out. On the main form is a selection of text boxes for the user to enter search filters against and then a command button for them to execute the search and another command button for them to empty/reset the search text boxes.
Below the text boxes is a subform (set to continuous form), which displays the search results.
On the main form is this public function which builds up the WHERE clause for an SQL statement that will be used to update the subform's RecordSource (i.e. pass what was entered in the text boxes on the main form to the WHERE clause for the subform's search results.:
Public Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
varWhere = Null
If Me.txtProspCode > "" Then
varWhere = varWhere & "[ProspectusCode] like " & tmp & "*" & Me.txtProspCode & "*" & tmp & " And "
End If
If Me.cboDeliveryOrg > "" Then
varWhere = varWhere & "[DeliveryOrganisation] like " & tmp & "*" & Me.cboDeliveryOrg & "*" & tmp & " And "
End If
If Me.cboLCdept > "" Then
varWhere = varWhere & "[LcDepartment] like " & tmp & "*" & Me.cboLCdept & "*" & tmp & " And "
End If
If Me.txtCollTitle > "" Then
varWhere = varWhere & "[ColloquialCourseTitle] like " & tmp & "*" & Me.txtCollTitle & "*" & tmp & " And "
End If
If Me.txtAimTitle > "" Then
varWhere = varWhere & "[LarsAimTitle] like " & tmp & "*" & Me.txtAimTitle & "*" & tmp & " And "
End If
If Me.txtAimRef > "" Then
varWhere = varWhere & "[LarsAimRef] like " & tmp & "*" & Me.txtAimRef & "*" & tmp & " And "
End If
If Me.cboCourseLevel > "" Then
varWhere = varWhere & "[CourseLevel] like " & tmp & "*" & Me.cboCourseLevel & "*" & tmp & " And "
End If
If Me.cboCourseType > "" Then
varWhere = varWhere & "[CourseType] like " & tmp & "*" & Me.cboCourseType & "*" & tmp & " And "
End If
If Me.cboAcYear > "" Then
varWhere = varWhere & "[Academic Year] like " & tmp & "*" & Me.cboAcYear & "*" & tmp & " And "
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
If Right(varWhere, 5) = " And " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
Also on the main form is the following code for when the user clicks the "search" button. It simply takes what was built for the WHERE clause in the above function and adds it to the appropriate place on the subform's RecordSource SQL statement:
Private Sub cmdSearch_Click()
Me.SearchSubForm.Form.RecordSource = "SELECT * FROM tblProspectus " & BuildFilter
Me.SearchSubForm.Requery
End Sub
And finally, also on the main form is the following code for when the user clicks the "clear search filters" button. It simply sets all search text boxes to 0-length strings and then sets the subform's record source to an empty row of results:
Private Sub cmdClear_Click()
Dim NoRecords As String
NoRecords = "SELECT " _
& "'' As ProspectusCode, " _
& "'' As DeliveryOrganisation, " _
& "'' As LcDepartment, " _
& "'' As LarsAimRef, " _
& "'' As LarsAimTitle, " _
& "'' As ColloquialCourseTitle, " _
& "'' As CourseLevel, " _
& "'' As CourseType, " _
& "'' As [Academic Year]"
Me.SearchSubForm.Form.RecordSource = NoRecords
Me.SearchSubForm.Requery
End Sub
Problems I'm having:
The "search" command is not returning any records when I try a search I know should return results in the subform. I've used Debug.Print Me.SearchSubForm.Form.RecordSource to see what was getting passed to the RecordSource and the SQL seemed fine to me... I even copy-pasted it in to the subform's Record Source manually in Design View and the form opened with the search results I was expecting... weird.
The "clear search filters" command works as long as I don't click the "search" command beforehand, otherwise it errors stating that the record source doesn't exist, quoting the SQL I passed in to the RecordSource for the "clear search filters" OnClick vba... again, weird. Almost as if the "Search" command's failure to produce records is causing an issue with any other attempt to change the subform's Record Source.
This subform, related command buttons and vba is working fine on a different main form! I'm pretty sure I've changed all references to this other main form I'm using...
Update:
I've found a workaround... I changed the table used in the SQL from a Table to a Query and now it seems to work fine... Don't know why though so would still appreciate any explanation.