Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2008, 04:43 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default How to do record count for Link table in access

Hi All

I've wrote a module, which does record count for each table in database

Question: How can only count records from linked table?
currently it does count records for each table in database.


Option Compare Database

Sub Recordsintables()

Dim x As Integer
Dim count As Integer
Dim Name As String


Dim i As Integer
Dim tables As String
Dim r As New ADODB.Recordset

'Debug.Print "Total Table In Database include system Table: " & CurrentDb.TableDefs.count

For i = 0 To CurrentDb.TableDefs.count - 1

    DoEvents

    tables = CurrentDb.TableDefs(i).Name
   If Left(tables, 4) <> "dbo_" And Left(tables, 4) <> "bak_" And Left(tables, 4) <> "MSys" Then

            Debug.Print "Table Name: " & tables & " - Count: " & recordcount(tables)

        End If
Next i

End Sub

Function recordcount(tbl As String) As Long
Dim c As New ADODB.Command
c.ActiveConnection = CurrentProject.Connection
c.CommandText = "select count(*) from [" + tbl + "]"
Dim r As ADODB.Recordset
Set r = c.Execute
r.MoveFirst
recordcount = r.Fields(0).Value
r.Close
End Function







Similar Threads
Thread Thread Starter Forum Replies Last Post
Record count deb1980 ASP.NET 2.0 Basics 6 April 10th, 2007 12:42 PM
can to link a ms access table to sql server? sugar SQL Server 2000 6 May 23rd, 2006 11:45 AM
Link Table In Access 2000 VB GURU Access VBA 6 March 16th, 2006 06:22 PM
RDS Single Record and Table Binding with Access qwerty Classic ASP Databases 0 July 15th, 2003 02:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.