I am not sure where I read it from but BAND is definitely in JET 4. Note
that my previous post mentioned that it may not work though the Query
interface or the code using DAO.
I did a quick little test code (using ADO, of course) in A2002:
****Code starts****
Public Sub Test_BAND()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT (4 BAND 4) As Test FROM Table1"
rs.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
With rs
While (rs.EOF) = False
Debug.Print rs.Fields("Test").Value
rs.MoveNext
Wend
End With
rs.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
****Code ends****
"Table1" can be any Table with some Records. When tested, it worked
correctly giving me a column of 4 (i.e. bitwise op) in the Debug window. If
I replace "BAND" with "AND" in the SQL String, I get a column of -1 (True,
i.e. logical op)!
In fact, in the SQL String, you don't even need the FROM clause and the SQL
String will give only one row (and only one column).
--
HTH
Van T. Dinh
MVP (Access)
"Sam Hobbs" wrote in message
...
"Van T. Dinh" wrote in message
...
In JET, I am fairly sure the "AND" is a purely logical operator. "BAND"
is
a
bitwise AND operator introduced in JET 4 but there may be problems using
it
in the Query interface. I am fairly sure BAND works in ADO code but you
will have to try it out.
Access says that BAnd is not valid as an operator and I can't find BAnd in
the list of functions for queries. However it probably helps a lot for me
to
realize that I should be able to use whatever works in SQL, so that is
what
I should look for. I should be able to get an answer relatively easily by
looking in forums and such for the SQL way to do this.
Note that in your result, -1 means True but this doesn't mean that it is
a
SystemObject since in Query, and expression like 1 AND 2 will
returns -1.
The reason is that any non-zero number is interpreted as True and only 0
is
interprested as False. So the above expression will be imterpreted as
True
AND True which results in True, i.e. -1.
Yes, I understand. That is how C/C++ works; at least, for the C/C++
logical
(boolean) operator "&&", 0 is false and anything that is not 0 is true.
|