Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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'][FONT='Calibri','sans-serif']code[/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")
Else
If strLetterDescription = "Volunteer reference chaser" Then
DoCmd.OpenQuery ("Update volunteer referee chaser date")
DoCmd.OpenQuery ("Append volunteer referee chaser data")
Else
If strLetterDescription = "TRAINING DATES" Then
DoCmd.RunMacro ("Set up training dates data for merge")
Else
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")
Else
If strLetterDescription = "Client Referee chaser" Then
DoCmd.OpenQuery ("qryUpdateClientRefereeChaserDate")
DoCmd.OpenQuery ("qryClientRefereechaser")
Else
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
'objApp.Activate
'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:="", _
'SubType:=wdMergeSubTypeAccess
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=\\10.0.0.20\SharedDocs\Age Concern Databases\Secured.mdw;", _
SQLStatement:="SELECT * FROM `mergetable`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
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
letterdata.MoveNext
Loop


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


objApp.Windows(strDocName).Activate
objApp.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
'objMMMD.Close SaveChanges:=False
'Set objMMMD = Nothing


'objApp.Documents.Open strDocName


objApp.Visible = True
objApp.Activate

End Sub[/font]
[FONT='Calibri','sans-serif']/code[/font]

Murray[/font]
Reply With Quote
  #2 (permalink)  
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
Default

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.
__________________
Thanks,

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.