View Single Post
  #2  
Old April 28th, 2010, 02:15 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Search form with a checkbox.

Joseluis -

I suspect you have a leading AND in your WHERE clause. Right before your
'Set rst' statement, add a debug.print line, like this:

Debug.print varWhere

The results will be in the immediate window when you step through the code.
I suspect your varWhere is "AND (Residentes = True), but if there are no
other prior conditions, it should just be (Residentes = True), that is,
without the AND. Since not all the code is in your posting, it is hard to
tell.

If this doesn't resolve it, post the value of the varWhere by copy/pasting
it from the immediate window (from the debug.print) into your next posting.

--
Daryl S


"JOSELUIS via AccessMonster.com" wrote:

There is a field in tblContacts named Residents.txt which is a yes/no field.
What I´m trying to create is a checkbox in my fdlgsearch [chkResidents] which
filters my records. I mean if [chkResidents] is not selected all the records
should appear but if [chkResidents] = True only the records in my
frmContacts that are residents should appear.
I have put the following code of a sample database but it doesn´t work.
Could anybody give me a hint ?

Private Sub cmdSearch_Click()
Dim varWhere As Variant
Dim rst As DAO.Recordset

' Initialize to Null
varWhere = Null
...
' Do Residentes next
If (Me.chkResidentes = True) Then
' Build a filter to include only resident contacts
varWhere = (varWhere + " AND ") & _
"(Residentes = True)"

Set rst = CurrentDb.OpenRecordset("SELECT tblContacts.* FROM tblContacts
WHERE " & varWhere)
Whenever I tryed to execute the search an Error # 3061#is displayed and
the code is interrupted in this line.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201004/1

.