Vb Problem

ipforlife

New member
Local time
Today, 04:19
Joined
May 12, 2006
Messages
8
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
 
What's the Error ?
 
compile error method or data not found, it highlights
Me.Contacts.Form.RecordSource = "SELECT * FROM qryContacts " & BuildFilter

But I have a form called contacts, you have to bear with me, I haven't programmed VB in 2 years
 
Try using

Me.recordSource = "SELECT * FROM qryContacts " & BuildFilter
 
got past that error, but now it pauses on

' Requery the subform
Me.Contacts.Requery

Thanks for all your help keith, maybe if you give me your email address, I can send you the file, it might be easier, i must admit though it is a very messy database, this weekend I will be cleaning it up
 
use me.Requery instead of me.Contacts.requery

Access knows that when you use the me keyword in a forms module that you are referring to the current form.
 

Users who are viewing this thread

Back
Top Bottom