Error # 3075

lmcc007

Registered User.
Local time
Today, 10:45
Joined
Nov 10, 2007
Messages
635
When the below code runs and there is no data, I get Error #3075 -- Syntax error (missing operator) in query expression '[CompanyID] = And [ActivityID] = 1'.


Code:
Public Function JobTotal(ByVal strActivity As Integer) As Integer

JobTotal = DCount("[ActivityID]", "Event", "[CompanyID]= " & Forms!frmViewJobList!txtCompanyID & " And " & _
        "[ActivityID]= " & CStr(strActivity))

End Function
How can I resolve this when there are no record (no activity yet for this record) to total?
 
When the below code runs and there is no data, I get Error #3075 -- Syntax error (missing operator) in query expression '[CompanyID] = And [ActivityID] = 1'.


Code:
Public Function JobTotal(ByVal strActivity As Integer) As Integer
 
JobTotal = DCount("[ActivityID]", "Event", "[CompanyID]= " & Forms!frmViewJobList!txtCompanyID & " And " & _
        "[ActivityID]= " & CStr(strActivity))
 
End Function
How can I resolve this when there are no record (no activity yet for this record) to total?

Consider using an If Statement to exclude any instances where Forms!frmViewJobList!txtCompanyID is Null. Something like the following might work for you:
Code:
    If (Forms!frmViewJobList!txtCompanyID Is Null) Then
        JobTotal = 0
    Else
        JobTotal = DCount("[ActivityID]", "Event", "[CompanyID]= " & _
            Forms!frmViewJobList!txtCompanyID & " And " & _
           "[ActivityID]= " & CStr(strActivity))
    End If
 
Consider using an If Statement to exclude any instances where Forms!frmViewJobList!txtCompanyID is Null. Something like the following might work for you:
Code:
    If (Forms!frmViewJobList!txtCompanyID Is Null) Then
        JobTotal = 0
    Else
        JobTotal = DCount("[ActivityID]", "Event", "[CompanyID]= " & _
            Forms!frmViewJobList!txtCompanyID & " And " & _
           "[ActivityID]= " & CStr(strActivity))
    End If

Now it gives me Error # 424: Object Required
 
Thanks boblarson,

I did:

If Not IsNull(Forms!frmViewJobList!txtCompanyID) Then...

in my form on the On Load Event. That did it.

Thanks for your reply!
 

Users who are viewing this thread

Back
Top Bottom