PC Review


Reply
Thread Tools Rate Thread

DCount multiple criteria (date range and text field)

 
 
KenR
Guest
Posts: n/a
 
      28th Aug 2008
I am trying to count the number of records in a table that meet a specified
date/time range in one field (EntryDate) and the username in a second field
(EntryBy).

'***********
Dim dtMin As Date
Dim dtmax As Date
Dim stUser As String
Dim intArrived As Integer
stUser = CurrentUser()
dtMin = #8/28/2008 9:05:01 AM#
dtmax = #8/28/2008 9:59:59 AM#
intArrived = DCount("*", "[Details]", "[EntryDate] Between #' & dtMin & '#
And #' & dtmax & '#' And [EntryBy] = stUser)
'******************

I get a syntax error when I try it, and can't figure out the correct syntax.

I'm using these static values in dtMin and dtMax for testing purposes; the
live code uses dMin and dMax functions to determine live values.

"Details" is the table
"EntryDate" is a date/time field with a general date format
"EntryBy" is a text field with 15 characters max

This code:
*********
intArrived = DCount("ID", "Details", "ShortEntryDate Between #" & dtMin & "#
And #" & dtmax & "#")
*********
works fine , but doesn't add the second criterion (current user) to find the
correct records, so the count includes records entered in that date range by
another person.

Can anyone help me with the syntax?

Thanks

KenR


 
Reply With Quote
 
 
 
 
dch3
Guest
Posts: n/a
 
      28th Aug 2008
Try something like...

intArrived = DCount("ID", "Details", "ShortEntryDate Between #" & dtMin & "#
And #" & dtmax & "#" & " AND [userNameField] = '[userName]'")

The WHERE statement is literally a SQL WHERE statement that allows ANDs, ORs
and other whatnot just keep adding the critiera as needed.


"KenR" wrote:

> I am trying to count the number of records in a table that meet a specified
> date/time range in one field (EntryDate) and the username in a second field
> (EntryBy).
>
> '***********
> Dim dtMin As Date
> Dim dtmax As Date
> Dim stUser As String
> Dim intArrived As Integer
> stUser = CurrentUser()
> dtMin = #8/28/2008 9:05:01 AM#
> dtmax = #8/28/2008 9:59:59 AM#
> intArrived = DCount("*", "[Details]", "[EntryDate] Between #' & dtMin & '#
> And #' & dtmax & '#' And [EntryBy] = stUser)
> '******************
>
> I get a syntax error when I try it, and can't figure out the correct syntax.
>
> I'm using these static values in dtMin and dtMax for testing purposes; the
> live code uses dMin and dMax functions to determine live values.
>
> "Details" is the table
> "EntryDate" is a date/time field with a general date format
> "EntryBy" is a text field with 15 characters max
>
> This code:
> *********
> intArrived = DCount("ID", "Details", "ShortEntryDate Between #" & dtMin & "#
> And #" & dtmax & "#")
> *********
> works fine , but doesn't add the second criterion (current user) to find the
> correct records, so the count includes records entered in that date range by
> another person.
>
> Can anyone help me with the syntax?
>
> Thanks
>
> KenR
>
>

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      28th Aug 2008
intArrived = DCount("*", "[Details]", "[EntryDate] Between #" & dtMin & "#
And #" & dtmax & "# And [EntryBy] = """ stUser & """")

--
Dave Hargis, Microsoft Access MVP


"KenR" wrote:

> I am trying to count the number of records in a table that meet a specified
> date/time range in one field (EntryDate) and the username in a second field
> (EntryBy).
>
> '***********
> Dim dtMin As Date
> Dim dtmax As Date
> Dim stUser As String
> Dim intArrived As Integer
> stUser = CurrentUser()
> dtMin = #8/28/2008 9:05:01 AM#
> dtmax = #8/28/2008 9:59:59 AM#
> intArrived = DCount("*", "[Details]", "[EntryDate] Between #' & dtMin & '#
> And #' & dtmax & '#' And [EntryBy] = stUser)
> '******************
>
> I get a syntax error when I try it, and can't figure out the correct syntax.
>
> I'm using these static values in dtMin and dtMax for testing purposes; the
> live code uses dMin and dMax functions to determine live values.
>
> "Details" is the table
> "EntryDate" is a date/time field with a general date format
> "EntryBy" is a text field with 15 characters max
>
> This code:
> *********
> intArrived = DCount("ID", "Details", "ShortEntryDate Between #" & dtMin & "#
> And #" & dtmax & "#")
> *********
> works fine , but doesn't add the second criterion (current user) to find the
> correct records, so the count includes records entered in that date range by
> another person.
>
> Can anyone help me with the syntax?
>
> Thanks
>
> KenR
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula for multiple criteria inc. date range J.Scargill Microsoft Excel Worksheet Functions 4 23rd Mar 2010 11:20 AM
multiple criteria date range Pat318 Microsoft Excel Worksheet Functions 4 17th Feb 2010 02:47 PM
Countif with multiple criteria and date range Pedro Dias Ferreira Microsoft Excel Worksheet Functions 12 13th Nov 2009 01:24 PM
Criteria range in a Dcount formula =?Utf-8?B?cGpv?= Microsoft Excel Misc 0 27th Jun 2007 03:54 PM
Null values in date range, multiple criteria =?Utf-8?B?TWFyayBpbiBNaWNoaWdhbg==?= Microsoft Access Queries 7 17th Aug 2006 06:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 AM.