I have a series of functions that return sql strings as variable rowsources depending on requirements.
For the most part these functions perform as expected except for one that refuses to work, "getCollSearch". see the code below.
When replaced by a query with the same sql the control performs properly, i.e. returns a dropdown list.
The only change made is the query /function selection in "setSources". No other code is altered.
How it works;
When the form opens it is populated with data starting with Genus and working from left to right as selections are made.
In essence the form is filtered by Genus and further filtered by each selection across the form.
In this format the "Collector" control's rowsource is controlled by function "getMColl", below, and it performs normally.
Clicking on the big blue button resets the form to start at either the "location" or "collector" controls and their rowsources are altered to accommodate this.
These changes are made by the "setSources" sub.
Now the form is initially filtered by Collector and/or Location and can be further filtered by the other controls
At form.load or a return to normal, left to right, operation the rowsources are set with "str = F".
It should be noted that my description makes sense to me. If it doesn't make sense to you, I'll try to explain it better. Just let me know what you don't get.
The code below is annotated.
Any variables associated with the functions have been removed for simplicity but the code below is what I have been testing.
For the most part these functions perform as expected except for one that refuses to work, "getCollSearch". see the code below.
When replaced by a query with the same sql the control performs properly, i.e. returns a dropdown list.
The only change made is the query /function selection in "setSources". No other code is altered.
How it works;
When the form opens it is populated with data starting with Genus and working from left to right as selections are made.
In essence the form is filtered by Genus and further filtered by each selection across the form.
In this format the "Collector" control's rowsource is controlled by function "getMColl", below, and it performs normally.
Clicking on the big blue button resets the form to start at either the "location" or "collector" controls and their rowsources are altered to accommodate this.
These changes are made by the "setSources" sub.
Now the form is initially filtered by Collector and/or Location and can be further filtered by the other controls
At form.load or a return to normal, left to right, operation the rowsources are set with "str = F".
It should be noted that my description makes sense to me. If it doesn't make sense to you, I'll try to explain it better. Just let me know what you don't get.
The code below is annotated.
Any variables associated with the functions have been removed for simplicity but the code below is what I have been testing.
Code:
'Sets the rowsources as required
Private Sub setSources(str As String)
If str = "F" Then
Me.RecordSource = sTable
Me.Multi_Search_subform.SourceObject = "query.MSearch"
Me.cboFamily.RowSource = getMFamily()
Me.cboGenus.RowSource = getMGenus()
Me.cboEpithet.RowSource = getMSpecies()
Me.cboCollector.RowSource = getMColl()
Me.cboLocality.RowSource = getMLocal()
Else
Me.cboCollector.RowSource = "QCollSearch" 'getCollSearch() 'If I use the query "QCollSearch" works. If I use the function "getCollSearch" doesn't
Me.cboLocality.RowSource = getLocalSearch()
Me.Multi_Search_subform.SourceObject = "query.maincollectorsearch"
End If
End Sub
'This is the code on the large blue button
Private Sub btnSearch_Click()
isLocal = True
setSources "L"
Me.cboFamily = ""
End Sub
'This is the cboCollector rowsource on load
Public Function getMColl() As String
sQry = "SELECT Herbarium_Collection.Collector " & _
"FROM Herbarium_Collection " & _
"GROUP BY Herbarium_Collection.Collector, Herbarium_Collection.Genus, Herbarium_Collection.SpeciesEpithet " & _
"HAVING Herbarium_Collection.Genus ALike [forms]![Multi-search]![cboGenus] & '%' " & _
"AND Herbarium_Collection.SpeciesEpithet ALike [forms]![Multi-search]![cboEpithet] & '%' " & _
"ORDER BY Herbarium_Collection.Collector, Herbarium_Collection.Genus;"
getMColl = sQry
End Function
'This is the cboCollector rowsource after btnSearch_Click.
'This function produces no results.
Public Function getCollSearch() As String
sQry = "SELECT herbarium_collection.Collector " & _
"FROM Herbarium_Collection " & _
"GROUP BY herbarium_collection.Collector " & _
"ORDER BY herbarium_collection.Collector;"
getCollSearch = sQry
End Function
'This is the SQL of query "QCollSearch" taken directly from function "getCollSearch" with obvious removals.
'This works
SELECT Herbarium_Collection.Collector
FROM Herbarium_Collection
GROUP BY Herbarium_Collection.Collector
HAVING (((Herbarium_Collection.Collector)>""))
ORDER BY Herbarium_Collection.Collector;