DCount Date Problem

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I keep getting Type Mismatch.....its gotta be the date!
Any help as always appreciated.
Thanks
DS

Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied", "PayApplied.PayDate
= Date(Now())" And "PayApplied.SalesID = " & Me.TxtSalesID & ""))
If IsNull(Me.TxtCount) Or _
 
Why bother trying to "calculate" Date(Now()), if you really only need
today's date? Instead, just use Date().

You might need to hang delimiters around that date -- Access uses the pound
sign ("#") to delimit date values. If you want to find a PayDate of today,
you're working with date values. Perhaps something like:

... "PayApplied.PayDate = #" & Date() & "# And ..."

(You don't say if your PayApplied.PayDate field is of a date/time data type
or not.)

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
DS said:
I keep getting Type Mismatch.....its gotta be the date!
Any help as always appreciated.
Thanks
DS

Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied", "PayApplied.PayDate
= Date(Now())" And "PayApplied.SalesID = " & Me.TxtSalesID & ""))
If IsNull(Me.TxtCount) Or _


It's probably because the quotes are out of whack.

Assuming that PayDate is a date type field:

Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied",
"PayDate >= Date() And SalesID = " & Me.TxtSalesID), 0)
 
Hi DS

There are a few problems here:

First, you use either Date() [current date] or Now() [current date and time]
but not both.

Second, your And should be inside the string, not between the two strings (I
suspect this is what is giving the error).

Third, the last [& ""] does nothing as it is simply appending an empty
string to what you already have.

Try this:
Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied", _
"PayApplied.PayDate = Date() And PayApplied.SalesID = " _
& Me.TxtSalesID), 0)

The last [, 0] is not strictly necessary but it ensures Nz returns a zero if
it processes a Null.

This means that the next line should be:
If Me.txtCount = 0 then ....
 
I keep getting Type Mismatch.....its gotta be the date!
Any help as always appreciated.
Thanks
DS

Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied", "PayApplied.PayDate
= Date(Now())" And "PayApplied.SalesID = " & Me.TxtSalesID & ""))
If IsNull(Me.TxtCount) Or _

You're mixing things up with the Date function. You don't need to -
and cannot! - pass it an argument, much less passing the Now()
argument.

To get today's date, use

Date()

To get the current date and time, accurate to the second, use

Now()

In neither case does the function take any argument.

John W. Vinson[MVP]
 
Graham said:
Hi DS

There are a few problems here:

First, you use either Date() [current date] or Now() [current date and time]
but not both.

Second, your And should be inside the string, not between the two strings (I
suspect this is what is giving the error).

Third, the last [& ""] does nothing as it is simply appending an empty
string to what you already have.

Try this:
Me.TxtCount = Nz(DCount("[PaymentID]", "PayApplied", _
"PayApplied.PayDate = Date() And PayApplied.SalesID = " _
& Me.TxtSalesID), 0)

The last [, 0] is not strictly necessary but it ensures Nz returns a zero if
it processes a Null.

This means that the next line should be:
If Me.txtCount = 0 then ....
That works! Thank you everyone for your help. Graham,John,Jeff and
Marshall...Your help is always appreciated!
Thanks
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Combining 2 DCounts 2
Loop and Insert Problem 5
Code Is Slow 3
Type Mismatch 1
Code Is Slow 6
DCount Syntax 2
DCount and NZ 6
Missing Operator 3

Back
Top