Checkboxes in DAO sql statement...HELP

N

NKK

Hello,
I have a form with a command button and an on-click event that runs the
following (there is a little more after the stop, but it is immaterial to
this question)

Private Sub cmdSetupNBS_Click()
Dim strwhereclase As String
Dim strformname As String
Dim db As Database
Dim rst As Recordset
Dim strsql As String
Dim msg As String

strwhereclause = "account_type_id = 'NBS'"

strsql = "SELECT dt_Accounts.Account_id FROM dt_Accounts "
strsql = strsql & "WHERE (((dt_Accounts.Account_setup)= 0) "
strsql = strsql & "AND ((dt_Accounts.Ready_to_create)= -1) "
strsql = strsql & "AND ((dt_Accounts.Account_type_id)='NBS'))"


Set db = CurrentDb
Set rst = db.OpenRecordset(strsql, dbOpenDynaset)
Debug.Print rst.RecordCount
Stop

I am getting 587 records in my recordset, however when I run the query via
the access query designer, I only get 4; 587 is the total number of records
that fit the last criteria (account_type_id = "NBS") so I am pretty sure my
syntax is off on the other two criteria. I have those fields set up in the
table as Yes/no fields with a format of yes/no. I have tried the following
values for ready_to_create and account_setup and keep getting the 587 record
count...
True, False
Yes, No
'yes', 'no'
-1, 0
What am I missing?
 
C

Clifford Bass

Hi,

It works fine for me in Access 2007 with DAO 3.6. You do have a
strwhereclase (without a u) defined, and a strwhereclause (with a u) used
later on. To prevent this problem, add the following line after the other
Option statement at the top of your module. It will cause Access to complain
about the usage of undefined variables.

Option Explicit

Clifford Bass
 

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

Top