Why won't this work?

  • Thread starter Thread starter Gator
  • Start date Start date
G

Gator

Private Sub Command2_Click()

Dim tot As Integer

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

End Sub
 
or this????

Private Sub Command2_Click()

Dim tot As Integer

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

End Sub
 
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.
 
just trying to provide an area where I can display the number of records from
a table in the DB....
 
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).
 
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
 
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!
 
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!
 
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")
 
Back
Top