Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Access 2003 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein; ISBN: 9780764559037
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2003 VBA Programmer's Reference 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 March 12th, 2009, 05:23 PM
Registered User
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How many rows in a table?

Environment WinXP Pro and MS Office 2003. I have been trying to find out how many rows there are in a table that is populated by queries run in VBA. I have tried the DAO code on pp 238/239 ('name'.EOF is not resolved) and also the approach on page 166 to get a record count. I am forced to wonder if I am missing some references. I have Visual Basic for Applications, MS Access 11.0 Object Library, OLE Automation, MS DAO 3.6 Object Library, MS Office 11.0 Object Library[FONT='Calibri','sans-serif'] , MS Word 11.0 Object Library and MS Office 1.0 RunTime Library[/font]
[FONT='Calibri','sans-serif']Is there another reference library I need to get EOF to work?[/font]
[FONT='Calibri','sans-serif']Here is the VBA stuff[/font]
[FONT='Calibri','sans-serif']Sub OpenWordDoc(strDocName As String, strLetterDescription As String, strFormName As String)
Dim objApp As Object
Dim objMMMD As Object
Dim db As Database
Dim letterdata As DAO.Recordset
Dim rownum As Integer
rownum = 0
Dim strCurrentFileName As String
On Error Resume Next
DoCmd.OpenQuery "Delete all rows from MergeTable"

'Load data to MergeTable with a query that collects the required data after update

If strFormName = "Volunteers" Then
If strLetterDescription = "Volunteer reference request" Then
DoCmd.OpenQuery ("Update volunteer referee letter date")
DoCmd.OpenQuery ("Append volunteer referee data")
If strLetterDescription = "Volunteer reference chaser" Then
DoCmd.OpenQuery ("Update volunteer referee chaser date")
DoCmd.OpenQuery ("Append volunteer referee chaser data")
If strLetterDescription = "TRAINING DATES" Then
DoCmd.RunMacro ("Set up training dates data for merge")
DoCmd.OpenQuery ("Volunteer letter data")
End If
End If
End If
End If
If strFormName = "Clients" Then
If strLetterDescription = "REFERENCE CLIENT" Then
DoCmd.OpenQuery ("qryUpdateClientRefereeLetterDate")
DoCmd.OpenQuery ("qryAppendClientRefereedata")
If strLetterDescription = "Client Referee chaser" Then
DoCmd.OpenQuery ("qryUpdateClientRefereeChaserDate")
DoCmd.OpenQuery ("qryClientRefereechaser")
DoCmd.OpenQuery ("qryClient")
End If
End If
End If
If strFormName = "Befrienders" Then
DoCmd.OpenQuery ("qryBefriender")
End If
strCurrentFileName = CurrentDb.Name
Set letterdata = db.OpenRecordset("MergeTable", dbOpenDynaset)

Set objApp = CreateObject("Word.Application")
objApp.Visible = False
'Set objMMMD = objApp.Documents.Open(FileName:=strDocName)

objApp.Documents.Open FileName:=strDocName, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False _
, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", XMLTransform:=""

'objApp.ActiveDocument.MailMerge.OpenDataSource Name:= _
'strCurrentFileName, _
'ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
'AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
'WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
'Connection:= _
'"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";U ser ID=Admin;Data Source=strCurrentFileName;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLE" _
', SQLStatement:="SELECT * FROM `mergetable`", SQLStatement1:="", _
Do While Not letterdata.EOF
rownum = rownum + 1
objApp.ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\All Users\Documents\Age Concern Databases\empty.odc", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password=""pixie 7826"";" & _
"User ID=Murray M-R;Data Source=" & strCurrentFileName & ";" & _
"Mode=Read;Jet OLEDB:System database=\\\SharedDocs\Age Concern Databases\Secured.mdw;", _
SQLStatement:="SELECT * FROM `mergetable`", SQLStatement1:="", _
With objApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
'.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
'.FirstRecord = wdDefaultFirstRecord
'.LastRecord = wdDefaultLastRecord
.FirstRecord = rownum
.LastRecord = rownum
End With
.Execute Pause:=False
End With

Dim intSplitName As Integer
Dim intLength As Integer
intLength = Len(strDocName)
intSplitName = InStrRev(strDocName, "\", , vbTextCompare)
strDocName = Right(strDocName, intLength - intSplitName)

objApp.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
'objMMMD.Close SaveChanges:=False
'Set objMMMD = Nothing

'objApp.Documents.Open strDocName

objApp.Visible = True

End Sub[/font]

Old April 20th, 2009, 07:21 PM
Authorized User
Join Date: Jul 2008
Location: Portland, OR, USA.
Posts: 38
Thanks: 1
Thanked 2 Times in 2 Posts

This is a bit old but just as an FYI for anyone following on. You can get the count of records from a table by using this:

DCount("*", "YourTableNameHere")

That is a very simple way.

Bob Larson
Access MVP (2008-2010, 2011)
Free Access tutorials, samples, tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move rows in a table bucky483 Javascript How-To 10 March 27th, 2017 12:57 AM
insert rows into the same table nik SQL Server 2000 1 October 26th, 2005 07:28 AM
Comparing certain rows in one table MrHicks Access 2 November 8th, 2004 04:00 PM
All rows in a table when in forms nigel_root Access VBA 3 June 2nd, 2004 03:52 PM
Q:Read two rows from table LegoMan ASP.NET 1.0 and 1.1 Basics 4 October 14th, 2003 01:22 PM

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