Hello all,
I think I’m going nuts. I am trying to use a function to provide the criteria for a query and am getting no results.
Here is the SQL:
Here is the function:
I have used stops and message boxes to determine the function is producing the correct criteria, as per this example:
But when the query runs, I get no records. I don’t do this very often, so I must be doing something wrong, but for the life of me I can’t see it.
Any help will, as always, be greatly appreciated.
LM
I think I’m going nuts. I am trying to use a function to provide the criteria for a query and am getting no results.
Here is the SQL:
Code:
SELECT tblComplaints.ComplaintInitiator, tblComplaints.ComplaintID, tblComplaints.ComplaintNum, tblComplaints.CustomerName, tblComplaints.ComplaintRcdDate, tblComplaints.DateSentToRespondees, tblComplaints.DateReSentToRespondees, tblComplaints.AreaId
FROM tblComplaints
WHERE (((tblComplaints.AreaId)=GetAreas()) AND ((tblComplaints.Status)="open"));
Here is the function:
Code:
Public Function GetAreas()
Dim cnn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim strCriteria As String
'Get user login Info
strUserLogin = fWin2KUserName()
UserName = DLookup("UserName", "qrySecurityInfo", "LogonID= '" & strUserLogin & "'")
Set cnn = CurrentProject.Connection
strSQL = "SELECT LogonID, AreaID "
strSQL = strSQL & "FROM qryUserAreas "
strSQL = strSQL & "WHERE LogonID = " & "'" & strUserLogin & "'"
rs.Open strSQL, cnn
If Not rs.EOF Then
rs.MoveFirst
'Begin Loop to generate criteria of multiple areas per person
strCriteria = " IN ("
Do While Not rs.EOF
strCriteria = strCriteria & rs!AreaId & ","
rs.MoveNext
Loop
rs.Close
strCriteria = strCriteria & ")"
Else
End If
If strCriteria = "" Then
GetAreas = ""
Else
GetAreas = strCriteria
End If
End Function
Code:
IN (26, 10, 41,)
Any help will, as always, be greatly appreciated.
LM