Trying to run a COUNT statement but having trouble

xMax

Registered User.
Local time
Today, 03:19
Joined
Aug 7, 2006
Messages
35
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?
 
Try this:

txtboxName = sqlstring

of this

TxtboxName=” COUNT (rowcount) FROM tbltable”

Please let me know.

Thanks
 
Last edited:
Both just makes the textbox say the statement rather than doing it.
 
Try dcount instead count.
I've just checked and it works perfect in mine

TxtboxName=” DCOUNT (rowcount) FROM tbltable”

jonyBravo
 
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
 

Users who are viewing this thread

Back
Top Bottom