Trouble with control DSUM (1 Viewer)

topdesk123

Registered User.
Local time
Today, 08:04
Joined
Mar 28, 2013
Messages
52
Hello all!

I am creating a payments form in which I need to lookup how much a person has paid this month. I am using 2 date fields on my form to determine the first and last day of the month (firstday, lastday) I have a field on my form called PaymentsMadeToday (means as of today actually) with the following as the control source:
Code:
=DSum("Amount","paymentT","LoanID=" & [LoanID] And [PaidDate] Between [firstday] And [lastday])
It produces #Name?. Without the date criteria, the amount will show up fine.

What am I missing? Thank you in advance.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:04
Joined
Feb 19, 2013
Messages
16,607
you don't have a complete string and your text form values need to be converted to dates in US format (mm/dd/yyyy) if not already in that format or converted to dates, try

=DSum("Amount","paymentT","LoanID=" & [LoanID] & " And [PaidDate] Between " & cdate([firstday]) & " And " & cdate([lastday]))
 

topdesk123

Registered User.
Local time
Today, 08:04
Joined
Mar 28, 2013
Messages
52
Thanks CJ London, unfortunately I don't get a result at all. I'm wondering if the problem could be my firstday and lastday fields are derived from:

Public Function FirstDayInMonth(Optional dtmdate As Variant) As Date
If IsMissing(dtmdate) Then
dtmdate = Forms!newpaymentform!ScheduleF.Form.DueDate
Debug.Print dtmdate


End If

FirstDayInMonth = DateSerial( _
Year(dtmdate), Month(dtmdate), 1)
End Function
Public Function lastdayinmonth(Optional dtmdate As Variant) As Date
lastdayinmonth = DateSerial( _
Year(dtmdate), Month(dtmdate) + 1, 0)
End Function

then the control source is: =firstdayinmonth(Date()) format is short date.
 

sneuberg

AWF VIP
Local time
Today, 08:04
Joined
Oct 17, 2014
Messages
3,506
You could try bypassing the [lastdate] and [firstdate] textboxes and calling the functions directly in your DCount. That might avoid any order in calculations problems. That would be:

Code:
=DSum("Amount", "paymentT", "LoanID=" & [LoanID] & " And [PaidDate] Between " & FirstDayInMonth(Date) & " And " & lastdayinmonth(Date))
 

Users who are viewing this thread

Top Bottom