Question : Access VBA DCount() on SQL 2008 server table

I'm having a weird problem when using a DCount() function in Access 2003 VBA.  

I'm trying to use a DCount() to check whether there are related records in a table but for dates > 01/01/2010 DCount() function just returns a 0.

For dates <= 01/01/2010 it works fine.

I'm using MS Access 2003 SP3 with a linked table to a SQL Server 2008 Express

The data type in SQL server is dateTime

I've also created a test table with just a few dates in 2009 and a few in 2010 and DCount() exhibits exactly the same behaviour.

Just to confirm that I'm using the correct syntext my VBA code is;

MsgBox DCount("[TestDate]", "dbo_tbltest", "[TestDate] = #02/01/2010#")

Can anyone else confirm this or offer some suggestions?


Thanks for looking

Answer : Access VBA DCount() on SQL 2008 server table

Hi CeramicPC,
In Access, SQL only recognises US date format, which is why I always throw it into a variable in code.
UK format (and in my case, AU) works almost everywhere else in Access according to your locale, but not in SQL.
Another tip is to include the # when you assign the date to the variable. This makes for prettier code when you you use it later...

Random Solutions  
 
programming4us programming4us