I have created a series of sql strings from stored queries.
The object being to reduce the number of queries doing essentially the same thing with a different table.
The sql strings utilise " " & sTable & " as A " construct.
In the code below,the functions getMFamily, getMGenus and getMColl work as expected.
The functions getMSpecies and getMLocal do not return a result.
If I replace the function calls in "setsoures" with the stored queries everything works.
The functions are in a module and "setsources" is in a form.
Where have I gone wrong?
The object being to reduce the number of queries doing essentially the same thing with a different table.
The sql strings utilise " " & sTable & " as A " construct.
In the code below,the functions getMFamily, getMGenus and getMColl work as expected.
The functions getMSpecies and getMLocal do not return a result.
If I replace the function calls in "setsoures" with the stored queries everything works.
The functions are in a module and "setsources" is in a form.
Where have I gone wrong?
Code:
Option Compare Database
Option Explicit
Private Sub setSources()
Dim str As String
Me.RecordSource = sTable
Me.cboFamily.RowSource = getMFamily(sTable)
Me.cboGenus.RowSource = getMGenus(sTable)
Me.cboEpithet.RowSource = getMSpecies(sTable)
Me.cboCollector.RowSource = getMColl(sTable)
Me.cboLocality.RowSource = getMLocal(sTable)
End Sub
Public Function getMFamily(sTable As String) As String
Dim sQry As String
sQry = "SELECT A.Family " & _
"FROM " & sTable & " as A " & _
"GROUP BY A.Family " & _
"HAVING ((Not (A.Family) Is Null)) " & _
"ORDER BY A.Family;"
getMFamily = sQry
End Function
Public Function getMGenus(sTable As String) As String
Dim sQry As String
sQry = "SELECT A.Genus, A.Family " & _
"FROM " & sTable & " as A " & _
"GROUP BY A.Genus, A.Family " & _
"HAVING (((A.Family) ALike [Forms]![Multi-search]![cboFamily] & ""%"")) " & _
"ORDER BY A.Genus;"
getMGenus = sQry
End Function
Public Function getMSpecies(sTable As String) As String
Dim sQry As String
sQry = "SELECT Herbarium_Collection.SpeciesEpithet " & _
"FROM " & sTable & " as A " & _
"GROUP BY A.SpeciesEpithet, A.Genus " & _
"HAVING (((A.SpeciesEpithet)>"") AND ((A.Genus) ALike [forms]![Multi-search]![cboGenus] & ""%"")) " & _
"ORDER BY A.SpeciesEpithet, A.Genus;"
getMSpecies = sQry
End Function
Public Function getMColl(sTable As String) As String
Dim sQry As String
sQry = "SELECT A.Collector " & _
"FROM " & sTable & " as A " & _
"GROUP BY A.Collector, A.Genus, A.SpeciesEpithet " & _
"HAVING (((A.Genus) ALike [forms]![Multi-search]![cboGenus] & ""%"") " & _
"AND ((A.SpeciesEpithet) ALike [forms]![Multi-search]![cboEpithet] & ""%"")) " & _
"ORDER BY A.Collector, A.Genus;"
getMColl = sQry
End Function
Public Function getMLocal(sTable As String) As String
Dim sQry As String
sQry = "SELECT A.Locality " & _
"FROM " & sTable & " as A " & _
"GROUP BY A.Locality, A.Collector, A.Genus, A.SpeciesEpithet " & _
"HAVING (((A.Collector) ALike [Forms]![Multi-search]![cboCollector] & ""%"") " & _
"AND ((A.Genus) ALike Nz([forms]![Multi-search]![cboGenus],"") & ""%"") " & _
"AND ((A.SpeciesEpithet) ALike Nz([forms]![Multi-search]![ccboEpithet],"") & ""%"")) " & _
"ORDER BY A.Locality, A.Genus, A.SpeciesEpithet;"
getMLocal = sQry
End Function