Run-Time error '3075' (1 Viewer)

cooh23

Registered User.
Local time
Today, 06:27
Joined
Dec 5, 2007
Messages
169
error " Syntax error (missing operator) in query experession '[DayCount] >1 AND'

I get that error after I type 1 under txtDayMin and nothing for txtDayMax

Here's my code in the search button

Code:
Option Compare Database



Private Sub btnClear_Click()
    Dim intIndex As Integer
    
    ' Clear all search items
    Me.txtODFNumber = ""
    Me.txtUserName = ""
    Me.txtODFScanDate = ""
    Me.txtfollow_up = ""
    Me.cmbStatus = ""
    Me.cmbQueue = ""
    Me.txtDayMin = ""
    Me.txtDayMax = ""
    
    
        
   
End Sub

Private Sub btnSearch_Click()
    ' Update the record source
    Me.frmSubODFSearch.Form.RecordSource = "SELECT * FROM qryODFData " & BuildFilter
    
    ' Requery the subform
    Me.frmSubODFSearch.Requery
End Sub

Private Sub Form_Load()
    
    ' Clear the search form
    btnClear_Click
    
End Sub

Private Function BuildFilter() As Variant
    Dim varWhere As Variant
    Dim varColor As Variant
    Dim varItem As Variant
  

    varWhere = Null  ' Main filter
  
    
    ' Check for ODF Number
    If Me.txtODFNumber > "" Then
        varWhere = varWhere & "[ODFNumber] LIKE """ & Me.txtODFNumber & "*"" AND "
    End If
    
    ' Check for UserName
    If Me.txtUserName > "" Then
        varWhere = varWhere & "[UserName] LIKE """ & Me.txtUserName & "*"" AND "
    End If
    
    ' Check for Date
    If Me.txtODFScanDate > "" Then
        varWhere = varWhere & "[ODFScanDate] LIKE """ & Me.txtODFScanDate & "*"" AND "
    End If
    
        ' Check for Date
    If Me.txtfollow_up > "" Then
        varWhere = varWhere & "[LastFollowup] LIKE """ & Me.txtfollow_up & "*"" AND "
    End If
    
    
    ' Check for Status
    If Me.cmbStatus > "" Then
        varWhere = varWhere & "[Status] LIKE """ & Me.cmbStatus & "*"" AND "
    End If
    
        ' Check for Queue
    If Me.cmbQueue > "" Then
        varWhere = varWhere & "[Queue] LIKE """ & Me.cmbQueue & "*"" AND "
    End If
    
            ' Check for Minimum Count Day
    If Me.txtDayMin > "" Then
        varWhere = varWhere & "[DayCount] > " & Me.txtDayMin & " AND"
    End If
    
            ' Check for Maximum Count Day
    If Me.txtDayMax > "" Then
        varWhere = varWhere & "[DayCount] < " & Me.txtDayMax & " AND "
    End If
    
    
    If IsNull(varWhere) Then
        varWhere = ""
    Else
        varWhere = "WHERE " & varWhere
        
        ' strip off last "AND" in the filter
        If Right(varWhere, 5) = " AND " Then
            varWhere = Left(varWhere, Len(varWhere) - 5)
        End If
    End If
    
    BuildFilter = varWhere
    
End Function

Everything else works except for searching for the minimum number and maximum number

Just an FYI, DayCount is a calculated field in the query. Not sure if that makes a difference

Here's my code under qryODFData:
Code:
SELECT tblODF.UserName, tblODF.ODFNumber, tblODF.Queue, tblODF.ODFScanDate, tblODF.Status, tblODF.LastFollowup, IIf(([Status]="Complete") Or ([Status]="Maturity") Or ([Status]="Agent is Aware of Pending") Or ([Status]="Licensing"),"-",Date()-[LastFollowup]) AS DayCount
FROM tblODF
ORDER BY tblODF.ODFScanDate;

Thank you,
 

boblarson

Smeghead
Local time
Today, 06:27
Joined
Jan 12, 2001
Messages
32,059
Don't use
If Me.txtDayMax > "" Then

Use

If Len(Me.txtDayMax & " ") > 0
 

cooh23

Registered User.
Local time
Today, 06:27
Joined
Dec 5, 2007
Messages
169

stopher

AWF VIP
Local time
Today, 14:27
Joined
Feb 1, 2006
Messages
2,395
The problem is in this bit...

Code:
    ' Check for Minimum Count Day
    If Me.txtDayMin > "" Then
        varWhere = varWhere & "[DayCount] > " & Me.txtDayMin & " AND"
    End If

Note there is no space after the AND in " AND". As the code is written it needs to be " AND " so that the AND removal bit will work.

CHris
 

cooh23

Registered User.
Local time
Today, 06:27
Joined
Dec 5, 2007
Messages
169
The problem is in this bit...

Code:
    ' Check for Minimum Count Day
    If Me.txtDayMin > "" Then
        varWhere = varWhere & "[DayCount] > " & Me.txtDayMin & " AND"
    End If

Note there is no space after the AND in " AND". As the code is written it needs to be " AND " so that the AND removal bit will work.

CHris

Chris,

I am now getting a different error:

Run-time error '3464'

"Data type mismatch in criteria expression"

When I try to debug the error, the code below is highlighted:
Code:
   Me.frmSubODFSearch.Form.RecordSource = "SELECT * FROM qryODFData " & BuildFilter

The only thing I could think of is that because DayCount is a calculated field in the query, but does that really matter?
 

cooh23

Registered User.
Local time
Today, 06:27
Joined
Dec 5, 2007
Messages
169
Chris,

I am now getting a different error:

Run-time error '3464'

"Data type mismatch in criteria expression"

When I try to debug the error, the code below is highlighted:
Code:
   Me.frmSubODFSearch.Form.RecordSource = "SELECT * FROM qryODFData " & BuildFilter

The only thing I could think of is that because DayCount is a calculated field in the query, but does that really matter?

I think I figured it out.. I had a table field named DayCount in one of the tables. So I changed the field name in qryODFData to Day_Count and in the module. It is working now...

I can't believe a small error like " AND" and " AND " could cause a lot of problem :eek:

Thank you,

John
 

stopher

AWF VIP
Local time
Today, 14:27
Joined
Feb 1, 2006
Messages
2,395
Good to hear you got it sorted.
Chris
 

Users who are viewing this thread

Top Bottom