Why won't this work?

G

Gator

Private Sub Command2_Click()

Dim tot As Integer

tot = DCount("*", "Deposits", "DateDep")
Text3.Text = tot

End Sub
 
G

Gator

or this????

Private Sub Command2_Click()

Dim tot As Integer

tot = DCount("*", "Deposits", "DateDep=#10/31/08#")
Text3.Text = tot

End Sub
 
K

Ken Snell \(MVP\)

What is Text3? What kind of object? Are you trying to set the value of a
field that is in the form's recordsource query or table? More details
please.
 
G

Gator

just trying to provide an area where I can display the number of records from
a table in the DB....
 
K

Klatuu

Leave off the .Text
It is valid only when the control has the focus. It really is more of a
holdover from Classic VB.

In VBA, Me.Text3 is sufficient (other than the name is meaningless and gives
no clue as to its use).
 
D

Douglas J. Steele

What does not working mean? Are you getting an error? If so, what's the
error? If you're not getting an error, what are you getting, and what do you
want to get instead?

The first one didn't work because the Where condition was invalid. This one,
though, is syntactically correct.

Note that there's no reason to use tot. The following should be sufficient:

Private Sub Command2_Click()

Text3.Text = DCount("*", "Deposits", "DateDep=#10/31/08#")

End Sub
 
D

Douglas J. Steele

Damn. It's the little details that catch you up each time! <g>

Thanks, Dave.
 
J

John W. Vinson

just trying to provide an area where I can display the number of records from
a table in the DB....

Don't use any VBA code AT ALL then; instead set the Control Source of Text3
(or rename the control to txtRecordCount if you want to preserve your sanity
when you revisit this database in six months) to

=DCount("*", "Deposits")

If you want the number of deposits on a particular date, you'll need to add a
third parameter to the DCount - just putting in DateDep won't work, because
the third argument needs to be a valid SQL WHERE clause. For today's date you
could use

=DCount("*", "Deposits", "[DateDep] = #" & Date() & "#")

but it's not clear what records you want to count!
 
G

Gator

all records....just trying to get the number of records in a table.

John W. Vinson said:
just trying to provide an area where I can display the number of records from
a table in the DB....

Don't use any VBA code AT ALL then; instead set the Control Source of Text3
(or rename the control to txtRecordCount if you want to preserve your sanity
when you revisit this database in six months) to

=DCount("*", "Deposits")

If you want the number of deposits on a particular date, you'll need to add a
third parameter to the DCount - just putting in DateDep won't work, because
the third argument needs to be a valid SQL WHERE clause. For today's date you
could use

=DCount("*", "Deposits", "[DateDep] = #" & Date() & "#")

but it's not clear what records you want to count!
 
J

John W. Vinson

all records....just trying to get the number of records in a table.

In that case I'll reiterate:

Don't use any VBA code AT ALL then; instead set the Control Source of Text3
(or rename the control to txtRecordCount if you want to preserve your sanity
when you revisit this database in six months) to

=DCount("*", "Deposits")
 

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

Top