That's a good point about bits not being portable. Using tinyint
certainly would have avoided this problem. I wonder what is the upside
to using bit instead of tinyint? Just being able to do boolean
comparisons?
Neil
It's not a glitch, it's a fundamental problem with the translation
between VB (8086) Booleans and SQL Server (PDP) bit fields.
I recommend Never Use Bit Fields, because bit fields aren't really
portable. Use small integer fields instead of bit fields. This is not
just VB and SQL Server: bit fields aren't portable even in C.
Of course, bit fields are normally portable if you only use the zero
value: from "Writing Solid Code": "the portable range of a bit field is
0",
but bit fields are still a problem waiting to happen.
So you can write:
strSQL = strSQL & " AND [Field1]=" & Me.Field1CheckBox
strSQL = strSQL & " AND NOT ([Field1]<>" & Me.Field1CheckBox
but unless I was having trouble with database size I wouldn't do that.
By the way, dates have the same problem as Booleans: if you
use a numeric representation for a date, Access will translate for
SQL Server when it recognises a translation is required: if you
put in date 1 you won't have a record with date 1.
(david)
Not quite that simple. For example, I have a form in one place that
has a series of check boxes that represent bit fields. If the user
wants to return records for which that field is true, they check the
box. The code looks something like:
strSQL = strSQL & " AND [Field1]=" & Me.Field1CheckBox
Thus, it takes the value of the check box and uses it in the dynamic
SQL. The values are -1 and 0, which the ODBC driver sent to SQL Server
as True and False. That code would have to be entirely rewritten.
(I've created a wraparound function that converts the checkbox 0
and -1 to 0 and 1; but it'll have to be applied to the entire
database, which is a ton of code.)
The bottom line here, in my opinion, is that the ODBC driver continues
to DISPLAY -1 for True for data retrieved FROM SQL Server, but
requires us to SEND 1 for True for criteria sent TO SQL Server. That
makes no sense, and seems to be a glitch. I was hoping there was some
sort of patch or fix.
Neil
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam
please)> wrote in message
Instead of testing for 1 or -1, you should test for <> 0; this way,
you won't have to chase a moving target.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
Have an Access MDB (2002/3 format) running against a SQL Server back
end, using ODBC linked tables. Recently upgraded from SQL 7 to SQL
2005.
With the bit fields in SQL Server, even though their values are 0
and 1 for False and True, the ODBC driver displays them as 0 and -1,
which are the Access False and True values. That was true for SQL 7
as well as for SQL 2005.
However, I find that when I run a query (not a pass-through; just a
regular Access query), I have to use "1" in the Where clause to get
True values from the SQL table, even though they are displayed
as -1!
For example, "Select * From MyTable Where SomeBitField=-1" returns
no records; but "Select * From MyTable Where SomeBitField=1" returns
records. However, the records show -1 in the bit field!!!!
If I use True instead of 1 or -1 it works fine. But I have tons of
code that build dynamic SQL that use -1 for true, and I'd have to
change all of those.
Also, since the above is true for saved queries as well as dynamic
SQL, it seems to be some sort of glitch (since the saved query would
have to have "1" in the Criteria field, but would display "-1" in
the results!).
Does anyone know if this is a known problem and if Microsoft
released a patch or whatever for this? I'm running Access 2003, SP3
(v. 11.8166.8221).
Thanks!
Neil