0

Hi, first of all sorry if I post this in the wrong section. Cant find where is the VBScript Section.

I'm new to VBScripting. What I need is the VBScript to count the number of record in my MSAccess table. I tried total = "SELECT COUNT(*) FROM Product" But it doesn't seems like working. There's a mismatch type error. I created another object and connect it to my MSAcess table and do a DO WHILE loop to count the number of record. Any other better suggestions??

Thanks...

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by raul15791
0

Try something like this. If first creates and sets a connection and recordset, opens the recordset (SELET * FROM [Product]) and then loops through the recordset, counter the number of records as it goes through the loop.

Dim cnn As ADODB.Connection
  Dim rst As ADODB.Recordset
  Dim queryString As String
  
  Set cnn = CurrentProject.Connection
  Set rst = New ADODB.Recordset

  queryString = "SELECT * FROM [Product]"
  rst.Open queryString, cnn

  dim counter as long
  counter = 0
  while not rst.eof
    counter = counter+1
    rst.movenext
  wend
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.