Dcount in a Form (1 Viewer)

Coldsteel

Registered User.
Local time
Today, 13:26
Joined
Feb 23, 2009
Messages
73
I have a form called Totals which has 2 text boxes.
One you enter a ID number. The textbox is called txtPS.
The other has my Dcount code. Called txttotals.

Code:
=DCount("[APPROVED]","tbl_sales","Seller =" & Forms!QuickStats!txtSeller And [APPROVED]="Approved" And [DATE REFERRED] Between DateSerial(Year(Date()),Month(Date()),1) And Now())


My code is not working I keep getting #Name?, any help would be greatly appreciated
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:26
Joined
Aug 30, 2003
Messages
36,129
You did not restart your string after the form reference, and you'll need to use single quotes around Approved (because you'll have all that inside double quotes, and those would confuse the issue).
 

Coldsteel

Registered User.
Local time
Today, 13:26
Joined
Feb 23, 2009
Messages
73
Sorry I am new to using the Dcount funcation, is this what you mean?

Code:

=DCount("[APPROVED]","tbl_sales","Seller =" & Forms!QuickStats!txtSeller And [APPROVED]='Approved' And [DATE REFERRED] Between DateSerial(Year(Date()),Month(Date()),1) And Now())
 

SOS

Registered Lunatic
Local time
Today, 11:26
Joined
Aug 27, 2008
Messages
3,517
=DCount("[APPROVED]","tbl_sales","Seller =" & Forms!QuickStats!txtSeller & " And [APPROVED]='Approved' And [DATE REFERRED] Between " & DateSerial(Year(Date()),Month(Date()),1) & " And " & Date())

And if Seller is text then it would need to be:

=DCount("[APPROVED]","tbl_sales","Seller ='" & Forms!QuickStats!txtSeller & "' And [APPROVED]='Approved' And [DATE REFERRED] Between " & DateSerial(Year(Date()),Month(Date()),1) & " And " & Date())
 
Last edited:

SOS

Registered Lunatic
Local time
Today, 11:26
Joined
Aug 27, 2008
Messages
3,517
And actually with the dates you might need:

=DCount("[APPROVED]","tbl_sales","Seller ='" & Forms!QuickStats!txtSeller & "' And [APPROVED]='Approved' And [DATE REFERRED] Between #" & DateSerial(Year(Date()),Month(Date()),1) & "# And #" & Date() & "#" )
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:26
Joined
Aug 30, 2003
Messages
36,129
If you're going to jump in, at least post correct code, eh? ;)

(misplaced #)
 

SOS

Registered Lunatic
Local time
Today, 11:26
Joined
Aug 27, 2008
Messages
3,517
If you're going to jump in, at least post correct code, eh? ;)

(misplaced #)
Can't tell if that is a friendly snipe or an angry one (and I fixed the location - it jumped on me just before I hit the post button - dang code I hate it when it doesn't cooperate :) )
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:26
Joined
Aug 30, 2003
Messages
36,129
Friendly; that's why I included the Canadian "eh" for you. :p
 

SOS

Registered Lunatic
Local time
Today, 11:26
Joined
Aug 27, 2008
Messages
3,517
Friendly; that's why I included the Canadian "eh" for you. :p
I rarely can tell what most of those darn smileys are doing. There are a few that are hard to miss but a few that are just plain confusing.
 

Coldsteel

Registered User.
Local time
Today, 13:26
Joined
Feb 23, 2009
Messages
73
Thanks for helping me out. I have been trying to implement this and I am getting a #error. I don’t know what I am doing wrong
 

Coldsteel

Registered User.
Local time
Today, 13:26
Joined
Feb 23, 2009
Messages
73
I figured out what I was doing wrong, I pasted the code incorrectly. Here is what worked for me

=DCount("[APPROVED]"," tbl_sales ","[Seller]=" & Forms!QuickStats!txtSeller & " And [APPROVED]='Approved' And [DATE REFERRED] Between #" & DateSerial(Year(Date()),Month(Date()),1) & "# And #" & Date() & "# ")

Thank you guys for all the help!!!!!
 

Users who are viewing this thread

Top Bottom