473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Why is DCount expression returning wrong values?

Hey everyone, I am a complete newb when it comes to programming and Access so bear with me. I developwed an application in Access 2007 to track tickets written for problems with our hardware (issue tracker). I want to count the number of tickets on and/or prior to a date entered in a text box. Here's what I got so far:

Expand|Select|Wrap|Line Numbers
  1. Dim enterdate As Date
  2.  
  3. enterdate = txtDate.Value
  4.  
  5. txtTotal.Value = DCount("*", "tblTickets", "[TicketDate] <=" & "#" & enterdate & "#")
Where txtTotal is another text box on the form to display the answer.

This code is executed by command button and when this function is ran it returns a completely wrong number.

Other pieces of information: Entries to the "TicketDate" column in tblTickets is formatted using the Now() function which, as you all know, returns not only the date but the time as well.

I am thinking that their needs to be some of conversion so that I get the correct number from this expression.

If anyone could shed some light on this, it would be greatly appreciated
Nov 1 '10 #1
6 3129
NeoPa
32,556 Expert Mod 16PB
I suspect it's more likely to be related to the format of a date literal in SQL. Check out Literal DateTimes and Their Delimiters (#).
Nov 1 '10 #2
So should I use the Format() function on the variable or the table column?
Nov 1 '10 #3
NeoPa
32,556 Expert Mod 16PB
Try something like this :
Expand|Select|Wrap|Line Numbers
  1. Me.txtTotal = DCount("*", _
  2.                      "tblTickets", _
  3.                      "[TicketDate] <= " & Format(Me.txtDate, "\#m/d/yyyy\#")
Nov 2 '10 #4
NeoPa,

Thank you for spending some time on this with me. The code you provided gives me an answer, but it is still the wrong one.

So I created a SQL query that essentailly does the same thing and the recordset it returns counts every single record EXCEPT the date you enter in txtDate field!

I tried hard coding a date into the VBA code you provided, and still the same thing.

I am still thinking that since the TicketDate column in my table is formatted using the "Now()" function, Access is also trying to calculate the time associated with the date. Is there a way to extract just the date in that column? Got any more ideas?
Nov 2 '10 #5
NeoPa
32,556 Expert Mod 16PB
That's because any DateTime value past midnight will always be greater than the simple Date value itself (which is numerically equivalent to midnight of that date).

Try instead :
Expand|Select|Wrap|Line Numbers
  1. Me.txtTotal = DCount("*", _
  2.                      "tblTickets", _
  3.                      "DateValue([TicketDate])<=" & Format(Me.txtDate, "\#m/d/yyyy\#")
A more sensible alternative of course, assuming you only want [TicketDate] and not [TicketDateTime], is to assign it the value of Date() rather than Now(). That way you needn't use DateValue() to trim off the time part as it won't be there.
Nov 2 '10 #6
NeoPa
32,556 Expert Mod 16PB
A new post was added that has been split off into its own thread (DCount() Confusion) because thread hijacking is not allowed.
Nov 9 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
10
by: andrew browning | last post by:
i have overlaoded all of my arithmetic operators but all are functioning as multiplication. below is a sample of the addition operator: Rational operator + (const Rational& r1, const Rational&...
7
by: Dean Earley | last post by:
I have the following code to get the number of seconds into a day given a date/time value: TValS = DateDiff("s", DateValue(StillDate), StillDate) StillDate is #04/05/2006 21:03:52#, and...
3
by: maflatoun | last post by:
Hi, I must be losing my mind why is the following code returning wrong values? var d = new Date(); alert(d); -> Fri Apr 7 09:28:18 EDT 2006 alert("Hour:" + d.getHours()); -> 9...
1
by: mosquito.dotnet | last post by:
I am getting clearly wrong values from TextBox.SelectionStart property in C# code. For example, if I move caret one character to right by pressing Keys.Right, sometimes declared SelectionStart...
7
by: arnuld | last post by:
/* C++ Primer - 4/e * * 1st example from section 7.2.2, page 234 * returning 2 values from a function * * STATEMENT: * to find a specific value in a vector and number of times * that...
1
by: Kjell Weding | last post by:
I have this code in VB.NET (VS 2005): Module kvitteringFunk Public Sub skrivKvittering() Dim KvittPrt As String = "" Dim iType As Byte = 0 KvittPrtType(iType, KvittPrt) ' iType should now...
2
by: Mayank1717 | last post by:
I am trying to change date into number format for that i am using formatnumber function but this function returning wrong result. for example : numeric value of 12/09/2007 is 39337 but it...
2
by: GaryDean | last post by:
The following command... string DebugString = System.Web.HttpContext.Current.Server.MapPath("App_Themes"); is executed from my ThemeManager.cs class in my App_code directory It returns......
2
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
I've been developing an application using Visual Studio 2005 for a few months, and suddenly it is returning hex values in the watchlist when I'm stepping through code to debug. Is there some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.