Run-Time 2580 error

Joined
Aug 17, 2011
Messages
1
Reaction score
0
I am trying to do a multiple filter on a subform and keep getting a Run-time 2580 error.

Here is my coding below.

Can anyone see any obvious errors??

I am new to coding so might be something really silly.

Cheers

Private Sub btnClear_Click()
Dim intIndex As Integer

' Clear all search items
Me.txtOperator = ""
Me.txtCountry = ""
Me.cmbAccountManager = 0


End Sub
Private Sub btnSearch_Click()

' Update the record source
Me.Main_Subform.Form.RecordSource = "SELECT * FROM MNO_Master " & BuildFilter

' Requery the subform
Me.Main_Subform.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
Dim intIndex As Integer
varWhere = Null ' Main filter
varColor = Null ' Subfilter used for colors

' Check for LIKE First Name
If Me.txtOperator > "" Then
varWhere = varWhere & "[Operator] LIKE """ & Me.txtOperator & "*"" AND "
End If

' Check for LIKE Last Name
If Me.txtCountry > "" Then
varWhere = varWhere & "[Country] LIKE """ & Me.txtCountry & "*"" AND "
End If



' Check for CompanyID
If Me.cmbAccountManager > 0 Then
varWhere = varWhere & "[Account Manager] = " & Me.cmbAccountManager & " AND "
End If





' Test to see if we have subfilter for colors...
If IsNull(varColor) Then
' do nothing
Else
' strip off last "OR" in the filter
If Right(varColor, 4) = " OR " Then
varColor = Left(varColor, Len(varColor) - 4)
End If

' Add some parentheses around the subfilter
varWhere = varWhere & "( " & varColor & " )"
End If

' Check if there is a filter to return...
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top