COUNT RECORD IN MDB...

sal21

Active Member
Joined
Apr 1, 2002
Messages
291
HOW,
I have an .mdb with a table TOTALE i would want to count the numer of the record and put the result in A2 of a sheet1
this is the path
e:\prova.mdb
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Look Sal,

I don't want to try to follow you around the internet from one board to another trying to find where you buggered off to next.

I posted a solution that works

here

http://www.ozgrid.com/forum/showthread.php?t=25917

and here

http://www.vbaexpress.com/forum/showthread.php?t=1250

Can you please cross-reference your cross-posts so that people don't waste their time on an issue already solved elsewhere. Thanks. It is only common courtesy.... a bit like ringing 5 taxi companies & pissing off in the first one that gets there.

Here's the code

Code:
Option Explicit 
 
Sub GetRecordCount() 
    Dim cnt As ADODB.Connection 
    Dim rst As ADODB.Recordset 
    Dim stDB As String, stSQL As String 
    Dim stConn As String 
    Dim wbBook As Workbook 
    Dim wsSheet As Worksheet 
    Dim i As Integer 
     
     'Instantiate the ADO-objects.
    Set cnt = New ADODB.Connection 
    Set rst = New ADODB.Recordset 
     
    Set wbBook = ThisWorkbook 
    Set wsSheet = wbBook.Worksheets(1) 
     
     'Path to the database.
    stDB = "C:\Will\Prova.mdb" 
     
     'Create the connectionstring.
    stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _ 
    & "Data Source=" & stDB & ";" 
     
     'The raw SQL-statement to be executed.
    stSQL = "SELECT DATA_CONT FROM TOTALE" 
     
    With cnt 
        .Open (stConn) 'Open the connection.
        .CursorLocation = adUseClient 'Necessary to disconnect the recordset.
    End With 
     
    With rst 
        .Open stSQL, cnt 'Create the recordset.
        Set .ActiveConnection = Nothing 'Disconnect the recordset.
        i = rst.RecordCount 
    End With 
     
    With wsSheet 
        .Cells(2, 1).Value = i 
    End With 
     'clean up
     
    rst.Close 
    Set rst = Nothing 
    cnt.Close 
    Set cnt = Nothing 
    Set wbBook = Nothing 
    Set wsSheet = Nothing 
     
End Sub
 
Upvote 0
WillR said:
Look Sal,

I don't want to try to follow you around the internet from one board to another trying to find where you buggered off to next.

I posted a solution that works

here

http://www.ozgrid.com/forum/showthread.php?t=25917

and here

http://www.vbaexpress.com/forum/showthread.php?t=1250

Can you please cross-reference your cross-posts so that people don't waste their time on an issue already solved elsewhere. Thanks. It is only common courtesy.... a bit like ringing 5 taxi companies & pissing off in the first one that gets there.

Here's the code

Code:
Option Explicit 
 
Sub GetRecordCount() 
    Dim cnt As ADODB.Connection 
    Dim rst As ADODB.Recordset 
    Dim stDB As String, stSQL As String 
    Dim stConn As String 
    Dim wbBook As Workbook 
    Dim wsSheet As Worksheet 
    Dim i As Integer 
     
     'Instantiate the ADO-objects.
    Set cnt = New ADODB.Connection 
    Set rst = New ADODB.Recordset 
     
    Set wbBook = ThisWorkbook 
    Set wsSheet = wbBook.Worksheets(1) 
     
     'Path to the database.
    stDB = "C:\Will\Prova.mdb" 
     
     'Create the connectionstring.
    stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _ 
    & "Data Source=" & stDB & ";" 
     
     'The raw SQL-statement to be executed.
    stSQL = "SELECT DATA_CONT FROM TOTALE" 
     
    With cnt 
        .Open (stConn) 'Open the connection.
        .CursorLocation = adUseClient 'Necessary to disconnect the recordset.
    End With 
     
    With rst 
        .Open stSQL, cnt 'Create the recordset.
        Set .ActiveConnection = Nothing 'Disconnect the recordset.
        i = rst.RecordCount 
    End With 
     
    With wsSheet 
        .Cells(2, 1).Value = i 
    End With 
     'clean up
     
    rst.Close 
    Set rst = Nothing 
    cnt.Close 
    Set cnt = Nothing 
    Set wbBook = Nothing 
    Set wsSheet = Nothing 
     
End Sub

... i am sorry but in this case i would want a quicly result ... Only for this.
For the pizza, you know, 4 pizza for you, for your patience:)
 
Upvote 0
Wanting a quick result is fair enough. That does not have to stop you from being courteous to people who offer you free help - it's really easy to x-reference your posts.
 
Upvote 0

Forum statistics

Threads
1,221,827
Messages
6,162,200
Members
451,753
Latest member
freddocp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top