upon editing a free search daabase I found on here to work with my company database, I get a VB error(highlighted in red) any ideas would be greatly appreciated
' *************************************
'
' Search Form Example
' by gromit
' 12-26-05
'
' You are free to adapt this for your own use
'
' *************************************
Option Compare Database
Option Explicit
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtFirstName = ""
Me.txtLastName = ""
Me.txtCompanyName = ""
Me.txtAddress = ""
Me.txtCountry = ""
Me.txtStateorProvince = ""
End Sub
Private Sub btnSearch_Click()
' Update the record source
Me.Contacts.Form.RecordSource = "SELECT * FROM qryContacts " & BuildFilter
' Requery the subform
Me.Contacts.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 varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE First Name
If Me.txtFirstName > "" Then
varWhere = varWhere & "[FirstName] LIKE """ & Me.txtFirstName & "*"" AND "
End If
' Check for LIKE Last Name
If Me.txtLastName > "" Then
varWhere = varWhere & "[LastName] LIKE """ & Me.txtLastName & "*"" AND "
End If
' Check for LIKE Company Name
If Me.txtCompanyName > "" Then
varWhere = varWhere & "[CompanyName] LIKE """ & Me.txtCompanyName & "*"" AND "
End If
' Check for LIKE Postal Code
If Me.txtAddress > "" Then
varWhere = varWhere & "[Address] LIKE """ & Me.txtAddress & "*"" AND "
End If
' Check for LIKE Country
If Me.txtCountry > "" Then
varWhere = varWhere & "[Country] LIKE """ & Me.txtCountry & "*"" AND "
End If
' Check for LIKE Province
If Me.txtProvince > "" Then
varWhere = varWhere & "[Province] LIKE """ & Me.txtProvince & "*"" AND "
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
' *************************************
'
' Search Form Example
' by gromit
' 12-26-05
'
' You are free to adapt this for your own use
'
' *************************************
Option Compare Database
Option Explicit
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtFirstName = ""
Me.txtLastName = ""
Me.txtCompanyName = ""
Me.txtAddress = ""
Me.txtCountry = ""
Me.txtStateorProvince = ""
End Sub
Private Sub btnSearch_Click()
' Update the record source
Me.Contacts.Form.RecordSource = "SELECT * FROM qryContacts " & BuildFilter
' Requery the subform
Me.Contacts.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 varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE First Name
If Me.txtFirstName > "" Then
varWhere = varWhere & "[FirstName] LIKE """ & Me.txtFirstName & "*"" AND "
End If
' Check for LIKE Last Name
If Me.txtLastName > "" Then
varWhere = varWhere & "[LastName] LIKE """ & Me.txtLastName & "*"" AND "
End If
' Check for LIKE Company Name
If Me.txtCompanyName > "" Then
varWhere = varWhere & "[CompanyName] LIKE """ & Me.txtCompanyName & "*"" AND "
End If
' Check for LIKE Postal Code
If Me.txtAddress > "" Then
varWhere = varWhere & "[Address] LIKE """ & Me.txtAddress & "*"" AND "
End If
' Check for LIKE Country
If Me.txtCountry > "" Then
varWhere = varWhere & "[Country] LIKE """ & Me.txtCountry & "*"" AND "
End If
' Check for LIKE Province
If Me.txtProvince > "" Then
varWhere = varWhere & "[Province] LIKE """ & Me.txtProvince & "*"" AND "
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