Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this query return a 3265 error?

Status
Not open for further replies.

AHJ1

Programmer
Oct 30, 2007
69
0
0
US
Can someone explain to me why this code works, but it does not work when I uncomment
Code:
Function GetCountOfRecs() As Integer
On Error GoTo err_GetCount
Dim strSQL As String
Dim intCount As Integer

intCount = ReturnSingleFieldData("qryCountOfMyDataAggregated", "CountOfID")
'intCount = ReturnSingleFieldData("qryActiveMyDataAgg", "CountOfID")
GetCountOfRecs = intCount
'debug.print "Count of Active Records = " & GetCountOfRecs

Exit Function
err_GetCount:
ErrBox "getting the count of active records in MyDataAggregated"
End Function

Here are the two SQL Statements
Code:
SELECT Count(MyDataAggregated.ID) AS CountOfID
FROM MyDataAggregated
GROUP BY MyDataAggregated.fInactive, MyDataAggregated.fSignedAndReady
HAVING (((MyDataAggregated.fInactive)=False) AND ((MyDataAggregated.fSignedAndReady)=True));
and
Code:
SELECT Count(MyDataAggregated.ID) AS CountOfID
FROM MyDataAggregated;
Obviously, it has something to do with the HAVING Clause.
 
ReturnSingleFieldData seems to be a user defined function... your error is likely in there.

If you right click it and hit definition it should take you to it.

If you need further help, please post that code.
 
Lameid,

Thanks for your response. Here's the code to that function. I do have a workaround, but I'd prefer not to use it.

Code:
Function ReturnSingleFieldData(strQueryName As String, strFieldName As String, _
Optional strParameterName1 As String, Optional varParmValue1 As Variant, _
Optional strParameterName2 As String, Optional varParmValue2 As Variant, _
Optional datDue As Date) As Variant

    Dim strMsg As String
    Dim qdf As DAO.QueryDef
    Dim rst As DAO.Recordset
    Dim strParameterName As String
  
    Set qdf = DBEngine(0)(0).QueryDefs(strQueryName)
    If Len(strParameterName1) >= 1 Then
        qdf.Parameters("" & strParameterName1 & "") = "" & varParmValue1 & ""
        If Len(strParameterName2) >= 1 Then
            qdf.Parameters("" & strParameterName2 & "") = "" & varParmValue2 & ""
        End If
    End If
    Set rst = qdf.OpenRecordset()
        If Not rst.EOF Then
            If Not IsNull(rst(strFieldName)) Then
                  ReturnSingleFieldData = rst(strFieldName).Value
                'End If
            Else
                ReturnSingleFieldData = ""
            'End If 'Added 12.1.08
            End If
        Else
            ReturnSingleFieldData = datDue
        End If
    qdf.Close
    rst.Close
    Set qdf = Nothing
    Set rst = Nothing
Exit Function
err_Import:
    Select Case Err.Number
        'Case 3021 'No current record
            'ReturnSingleFieldData
            'Resume Next
        Case 3265
             ReturnSingleFieldData = ""
        Case Else
            errbox "returning the value of a single field in a table from the function ReturnSingleFieldData."
    End Select
    Exit Function
End Function
 
You were right. Thanks. Have a star!
I made the mistake of grabbing code from a different project without totally proofing it. In this snippet I have a datDue
I changed it to a zero.
Code:
Set rst = qdf.OpenRecordset()
        If Not rst.EOF Then
            If Not IsNull(rst(strFieldName)) Then
                  ReturnSingleFieldData = rst(strFieldName).Value
                'End If
            Else
                ReturnSingleFieldData = ""
            'End If 'Added 12.1.08
            End If
        Else
            ReturnSingleFieldData = datDue
        End If

Code:
 ReturnSingleFieldData = 0
Works like a charm now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top