Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-15-2008, 12:33 PM
=?Utf-8?B?QWRhbSBUaHdhaXRlcw==?=
 
Posts: n/a
Dcount help - counting by month

I give up on this one, can anyone help?

DCount("*", "tbl_MAIN", Format("[SaveDate]", "yyyymm") = Format(Date,
"yyyymm"))

I'm trying to count all records in tbl_Main that have a SaveDate in this
month. This formula above just gives 0, and any alteration just result in a
'list seperator or )' error. Any ideas?

Thanks!

--
Adam Thwaites
Access Database Designer
adam.thwaites.remove@thisbit.mercedes.co.uk
Manchester, UK
Reply With Quote
  #2 (permalink)  
Old 05-15-2008, 01:09 PM
=?Utf-8?B?Q2hlZXNlX3doaXo=?=
 
Posts: n/a
RE: Dcount help - counting by month

Hi Adam,

Try this:

DCount("[SaveDate]", "tblMain", "Month([SaveDate]) = Month(Date())")

CW

"Adam Thwaites" wrote:

> I give up on this one, can anyone help?
>
> DCount("*", "tbl_MAIN", Format("[SaveDate]", "yyyymm") = Format(Date,
> "yyyymm"))
>
> I'm trying to count all records in tbl_Main that have a SaveDate in this
> month. This formula above just gives 0, and any alteration just result in a
> 'list seperator or )' error. Any ideas?
>
> Thanks!
>
> --
> Adam Thwaites
> Access Database Designer
> adam.thwaites.remove@thisbit.mercedes.co.uk
> Manchester, UK

Reply With Quote
  #3 (permalink)  
Old 05-15-2008, 04:27 PM
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
 
Posts: n/a
RE: Dcount help - counting by month

It’s a little tricky getting it right because the arguments of the DCount
function are each a string expression, the format pattern argument of the
Format pattern is also a string expression, and the Format function returns a
string expression, so when building the whole expression contiguous pairs of
quotes have to be used to represent the literal quotes characters, like so:

DCount("*", "tbl_MAIN", "Format(SaveDate,""yyyymm"") = """ &
Format(Date,"yyyymm") & """")

Alternatively you can us CW's approach, but you need to call the Year
function as well as the Month function or rows from the same month in every
year represented in the table will be counted:

DCount("*", "tbl_MAIN", "Year(SaveDate) = " & Year(Date) & " And
Month(SaveDate) = " & Month(Date))

Each of the above is a single line of code of course; they might well be
split over two lines by your newsgroup reader.

Ken Sheridan
Stafford, England

"Adam Thwaites" wrote:

> I give up on this one, can anyone help?
>
> DCount("*", "tbl_MAIN", Format("[SaveDate]", "yyyymm") = Format(Date,
> "yyyymm"))
>
> I'm trying to count all records in tbl_Main that have a SaveDate in this
> month. This formula above just gives 0, and any alteration just result in a
> 'list seperator or )' error. Any ideas?
>
> Thanks!
>
> --
> Adam Thwaites
> Access Database Designer
> adam.thwaites.remove@thisbit.mercedes.co.uk
> Manchester, UK


Reply With Quote
  #4 (permalink)  
Old 05-15-2008, 04:31 PM
=?Utf-8?B?Q2hlZXNlX3doaXo=?=
 
Posts: n/a
RE: Dcount help - counting by month

Ken,

I posted so fast I forgot about the years. Thanks for catching that!

CW

"Ken Sheridan" wrote:

> It’s a little tricky getting it right because the arguments of the DCount
> function are each a string expression, the format pattern argument of the
> Format pattern is also a string expression, and the Format function returns a
> string expression, so when building the whole expression contiguous pairs of
> quotes have to be used to represent the literal quotes characters, like so:
>
> DCount("*", "tbl_MAIN", "Format(SaveDate,""yyyymm"") = """ &
> Format(Date,"yyyymm") & """")
>
> Alternatively you can us CW's approach, but you need to call the Year
> function as well as the Month function or rows from the same month in every
> year represented in the table will be counted:
>
> DCount("*", "tbl_MAIN", "Year(SaveDate) = " & Year(Date) & " And
> Month(SaveDate) = " & Month(Date))
>
> Each of the above is a single line of code of course; they might well be
> split over two lines by your newsgroup reader.
>
> Ken Sheridan
> Stafford, England
>
> "Adam Thwaites" wrote:
>
> > I give up on this one, can anyone help?
> >
> > DCount("*", "tbl_MAIN", Format("[SaveDate]", "yyyymm") = Format(Date,
> > "yyyymm"))
> >
> > I'm trying to count all records in tbl_Main that have a SaveDate in this
> > month. This formula above just gives 0, and any alteration just result in a
> > 'list seperator or )' error. Any ideas?
> >
> > Thanks!
> >
> > --
> > Adam Thwaites
> > Access Database Designer
> > adam.thwaites.remove@thisbit.mercedes.co.uk
> > Manchester, UK

>

Reply With Quote
  #5 (permalink)  
Old 05-15-2008, 06:54 PM
Rick Brandt
 
Posts: n/a
Re: Dcount help - counting by month

Adam Thwaites wrote:
> I give up on this one, can anyone help?
>
> DCount("*", "tbl_MAIN", Format("[SaveDate]", "yyyymm") = Format(Date,
> "yyyymm"))
>
> I'm trying to count all records in tbl_Main that have a SaveDate in
> this month. This formula above just gives 0, and any alteration just
> result in a 'list seperator or )' error. Any ideas?
>
> Thanks!



Criteria should be applied to fields, not expressions based on fields.

More efficient than other alternatives would be...

Dim whr as String
whr = "SaveDate >= DateSerial(Year(Date()), Month(Date()), 1) " & _
"AND SaveDate < DateSerial(Year(Date()), Month(Date()) + 1, 1)"

DCount("*", "tbl_MAIN", whr)


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


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



All times are GMT. The time now is 11:50 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
CreditCards | Buy Anything On eBay | Loans | Bleach Episodes | Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114