View Full Version : Trying to run a COUNT statement but having trouble


xMax
08-09-2006, 10:40 AM
I have a text box and I am trying to count a certain number of rows. Suppose the textbox is called txtnumrows

My SQL Statements are as follows: (the rest is probably unimportant)

Dim sqlstring as String

sql string = "SELECT COUNT (rowcount) FROM tbltable"

DoCmd.RunSQL (string)

I have tried with a query and some other stuff. How do I make it so that the textbox will understand the SQL statement and display the number of rows in the table?

xMax
08-11-2006, 04:08 AM
Anyone?? This is work related.

JonyBravo
08-11-2006, 05:27 AM
Try this:

txtboxName = sqlstring

of this

TxtboxName=” COUNT (rowcount) FROM tbltable”

Please let me know.

Thanks

xMax
08-11-2006, 06:38 AM
Both just makes the textbox say the statement rather than doing it.

JonyBravo
08-11-2006, 07:01 AM
Try dcount instead count.
I've just checked and it works perfect in mine

TxtboxName=” DCOUNT (rowcount) FROM tbltable”

jonyBravo

xMax
08-11-2006, 07:17 AM
It still doesn't seem to work.

JonyBravo
08-12-2006, 01:28 AM
I've created:
1 - form called frmtest
2 - 2 text box call txttest & txtYearBorn
3 - button
4 - table called tbltest with field names ID & Name & Year born

Then I written on the form frmtest the following code:

Option Compare Database
Option Explicit

Function test()
txttest = DCount("[Name]", "tbltest")
End Function

Private Sub Command2_Click()
Call test
End Sub

Everytime you click the button, text box will tell you how many name are in the table tbltest.
If you want to do something more complex, you can do something like it:

txttest = DCount("[Name]", "tbltest", [Year born]= ' " & txtYearBorn & " ')
It will count you only the number of people that born on the year inserted on txtYearBorn.

Hope this can help you

JonyBravo