|
-
Feb 21st, 2005, 03:34 PM
#1
Re: Getting RecordCount
But doesnt it work for the .LastRecord = .RecordCount?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 21st, 2005, 03:40 PM
#2
Re: Getting RecordCount
nope. just works with the -1
-
Feb 21st, 2005, 03:46 PM
#3
Re: Getting RecordCount
It works for mine so I double checked in the help file and this its what I found.
If Microsoft Word cannot determine the number of records in a data source, the RecordCount property will return a value of -1
So it may depend on the way datasource was setup or if its a complex query???
What is your datasource? .odc?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 21st, 2005, 03:49 PM
#4
Re: Getting RecordCount
I've used this very non-standard trick at times to arrive at a recordcount - if the number of rows in the table is low - it won't matter that this is a ugly query...
Code:
Select [First Name], [Last Name], [Mailing Address], City, State, Zip
,(Select Count(*) From [My Temp]) From [MyTemp]
Thus getting the recordcount as a column in the recordset itself...
-
Feb 21st, 2005, 03:54 PM
#5
Re: Getting RecordCount
It actually works for the complex query that isn't part of the mailmerge. (the one that sends email or printer output) I guess that I'll have to do a separate query to get the count. That's what I was trying to avioid if it wasn't necessary.
Thanks
-
Feb 21st, 2005, 03:59 PM
#6
Re: Getting RecordCount
If you are going to go the separate query route, then my technique guarantees that the recordcount will truly match the row count in the "data" recordset. If you do two separate queries, then you could run the risk of row counts changing during the operation. We would have that happen in our applications - they load lots of rows in a given day!
-
Feb 21st, 2005, 04:18 PM
#7
Re: Getting RecordCount
How do I refer to the Count() field in my RS ? I forgot that I had already done it with the complex query. Now I need it for the simple query. If I can add the count like szlammy said, I'd like to do that.
EDIT: I have this
VB Code:
rs.Open "Delete TempTable .* from TempTable ", cn, adOpenKeyset, adLockOptimistic, adCmdText
rs.Open "INSERT INTO TempTable (RecCount) " & _
"SELECT Count(*)" & _
"From FarmingTemp", cn, adOpenKeyset, adLockOptimistic, adCmdText
RecCount = rs.Fields(1)
So how do I get it back out. I've also tried RecCount = rs.fields("RecCount") but that returns an error.
Last edited by dglienna; Feb 21st, 2005 at 04:37 PM.
-
Feb 21st, 2005, 04:41 PM
#8
Re: Getting RecordCount
I think I figured it out:
VB Code:
rs.Open "select RecCount from TempTable", cn, adOpenKeyset, adLockOptimistic, adCmdText
RecCount = rs.Fields("RecCount")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|