narrow default width wide
colour style colour style colour style colour style

VBA to perform bitwise comparisons

More lessons learned from my account cleanup efforts...

Here is a function you can use to do bitwise comparisons. This is a function I am using in MSAccess for a couple of things to help write queries against AD.

Function SQL_And(Num1 As Long, Num2 As Long) As Long
  SQL_And = (Num1 And Num2)
End Function

Here's the SQL syntax I am using to find Disabled accounts:

SELECT SQL_And(2,ADUsers.userAccountControl) AS Expr1, *
WHERE (((SQL_And(2,[ADUsers].[userAccountControl]))=2));

Here's what I am using to find accounts with password expiration disabled:

SELECT SQL_And(65536,ADUsers.userAccountControl) AS Expr1, *
WHERE (((SQL_And(65536,[ADUsers].[userAccountControl]))=65536));

I mentioned in my other recent VBA post that it took me 4 hours to get a simple function working. This one is even worse....a one line function took me about 6 hours to get working correctly. Most of the time was doing research and trying to get it to work using straight SQL instead of calling a function...It's amazing how sometimes you can crank out 100's of lines of code in a couple of hours but one thing can stump you for hours and hours...