View Single Post
  #5  
Old October 26th, 2008, 01:22 PM posted to microsoft.public.access
jon
external usenet poster
 
Posts: 640
Default How to count duplicated date

Thank you Rick, but does not wok as well

"Rick Brandt" wrote:

Scott Lichtenberg wrote:
Jon,

Try SQL instead of the Dcount.

Dim db as Database
Dim rs as Recordset
Dim strSQL as String

Set db = CurrentDb

'Set up SQL string . Note the format for date fields in Access -
#01/01/2008#
strSQL = "SELECT COUNT(*) AS DateCount FROM MyTable WHERE ndate = #" &
Me!MyField & "#"

Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

If rs.Recordcount = 0 Then
MsgBox "Date Not Found"
Else
MsgBox "Date Found. Number of occurances is: " & rs!DateCount
End If

Set rs = Nothing
Set db = Nothing


Why would you substitute all of those lines of code for a simple DCount()
one-liner?

To Jon, you do not need to use Nz() around your DCount() because DCount()
never returns Null. This should work...

MsgBox DCount("*", "[dd]", "[ndate] = #" & Me.aa & "#")

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com