Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Docmd.runsql problem 1

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
I run this code to find out how many records there are in the table

docmd.runsql ("select count (*) as intX from table1")
but vba gives an error A RUNSQL ACTION REQUIRES AN ARGUMENT CONSISTING OF AN SQL STATEMENT

How else would I get the number of the records in the table from the code?
 
sabavno,

try: lngTotalRecs = DCount("[field]", "Table", "")

hth,
Wayne
 
Try

Dim intX as Integer


intX = DCount ("*", "Table1")

You can add an extra parameter after "Table1" to specify which records should be included.

eg intX = DCount ("*", "Table1", "LastName='Smith'")

It is worth knowing about domain aggregate functions like DCount, DSum, DMax, DMin, DAvg etc, -they are really handy for doing things like this.

John
 
Hi

You caan use DoCmd.RunSQL ONLY for an action query, not a SELECT query.

You need to use DCount as per the other two posts of create a recordset.

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top