PC Review


Reply
Thread Tools Rate Thread

Using "OpenRecordset" on Linked Table Issue

 
 
Gary
Guest
Posts: n/a
 
      25th Sep 2009
I am using Access 2000-2003 on XP Pro OS.

I have a linked table, and there are 3 records in that linked table.

When I try to check on the number of records it only show 1.

This is my VBA Code:

Dim db As Database
Dim T As DAO.Recordset
Dim x As Integer

Set db = CurrentDb()
Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)

x = T.RecordCount


I have tried dbOpenTable, dbOpenSnapshot, etc and they all show 1 record.
If I change the table from link to a regular table, I see 3 records.

When I open the linked tabe, I see 3 records. I reference are set correct
for DAO. (i.e. DAO 3.6)

Can someone please help.

Thanks You,


Gary
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      25th Sep 2009
"Gary" <(E-Mail Removed)> wrote in message
news:E9467F8F-B41C-47DB-AF5F-(E-Mail Removed)...
>I am using Access 2000-2003 on XP Pro OS.
>
> I have a linked table, and there are 3 records in that linked table.
>
> When I try to check on the number of records it only show 1.
>
> This is my VBA Code:
>
> Dim db As Database
> Dim T As DAO.Recordset
> Dim x As Integer
>
> Set db = CurrentDb()
> Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
>
> x = T.RecordCount
>
>
> I have tried dbOpenTable, dbOpenSnapshot, etc and they all show 1 record.
> If I change the table from link to a regular table, I see 3 records.
>
> When I open the linked tabe, I see 3 records. I reference are set
> correct
> for DAO. (i.e. DAO 3.6)



For a dynaset-type recordset, the RecordCount property is only reliable when
you have moved to the end of the recordset. Effectively, it's a count of
the records accessed so far, not necessarily the total number of records in
the recordset. If you need to know how many records are in the recordset,
try this:

Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
With T
If Not .EOF Then
.MoveLast
.MoveFirst
End If
x = .RecordCount
End With

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      25th Sep 2009
RecordCount usually isn't accurate until you've gone to the end of the
recordset.

Dim db As Database
Dim T As DAO.Recordset
Dim x As Integer

Set db = CurrentDb()
Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
T.MoveLast
x = T.RecordCount


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gary" <(E-Mail Removed)> wrote in message
news:E9467F8F-B41C-47DB-AF5F-(E-Mail Removed)...
>I am using Access 2000-2003 on XP Pro OS.
>
> I have a linked table, and there are 3 records in that linked table.
>
> When I try to check on the number of records it only show 1.
>
> This is my VBA Code:
>
> Dim db As Database
> Dim T As DAO.Recordset
> Dim x As Integer
>
> Set db = CurrentDb()
> Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
>
> x = T.RecordCount
>
>
> I have tried dbOpenTable, dbOpenSnapshot, etc and they all show 1 record.
> If I change the table from link to a regular table, I see 3 records.
>
> When I open the linked tabe, I see 3 records. I reference are set
> correct
> for DAO. (i.e. DAO 3.6)
>
> Can someone please help.
>
> Thanks You,
>
>
> Gary



 
Reply With Quote
 
Banana
Guest
Posts: n/a
 
      25th Sep 2009
Be aware that a .Movelast can be particularly expensive, especially if
we're opening a large recordset.

If all you want to verify there is at least a record in there, then you
only need to test for .BOF and .EOF (or just .EOF, but I'm a
belt-and-suspend kind of guy):

If Not(T.BOF And T.EOF) Then
... <there's a record in there...>
Else
<It's empty>
End If

OTOH, if you want to get a count of records, it may be faster to open a
COUNT(*) query against the same table with same criteria as the recordset.


Douglas J. Steele wrote:
> RecordCount usually isn't accurate until you've gone to the end of the
> recordset.
>
> Dim db As Database
> Dim T As DAO.Recordset
> Dim x As Integer
>
> Set db = CurrentDb()
> Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
> T.MoveLast
> x = T.RecordCount
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      25th Sep 2009
Actually, I believe RecordCount will always be non-zero if there's any data
in the recordset, and zero if there isn't.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Banana" <Banana@Republic> wrote in message
news:4ABD01BB.7010606@Republic...
> Be aware that a .Movelast can be particularly expensive, especially if
> we're opening a large recordset.
>
> If all you want to verify there is at least a record in there, then you
> only need to test for .BOF and .EOF (or just .EOF, but I'm a
> belt-and-suspend kind of guy):
>
> If Not(T.BOF And T.EOF) Then
> ... <there's a record in there...>
> Else
> <It's empty>
> End If
>
> OTOH, if you want to get a count of records, it may be faster to open a
> COUNT(*) query against the same table with same criteria as the recordset.
>
>
> Douglas J. Steele wrote:
>> RecordCount usually isn't accurate until you've gone to the end of the
>> recordset.
>>
>> Dim db As Database
>> Dim T As DAO.Recordset
>> Dim x As Integer
>>
>> Set db = CurrentDb()
>> Set T = db.OpenRecordset("Missing Formations", dbOpenDynaset)
>> T.MoveLast
>> x = T.RecordCount
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 - Copy linked table to a local table or have linked tableas read-only Stuart Microsoft Access 0 26th May 2012 10:28 PM
ACCESS table linked to EXCEL spreadsheet. How to know which table is linked? Art Microsoft Access 3 2nd Apr 2007 12:51 PM
ACCESS table linked to EXCEL spreadsheet. How to know which table is linked? Art Microsoft Excel Discussion 3 1st Apr 2007 10:14 PM
Help updating table from linked table(linked table is a csv) Thierry Microsoft Access Queries 2 29th Jun 2004 02:21 PM
UPDATE a linked access table with value from a ODBC linked SQL table JB Microsoft Access 0 18th Nov 2003 10:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:53 PM.