Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: recordsetclone not working

Geek News

recordsetclone not working
Cmenkedi 12/10/2008 8:37:02 PM
Hello,
I am hiving trouble with recordsetclone.
I have a form that I open and want to display the number of records. The
code that I am using is:
Set rst = Me.RecordsetClone
Me.txtRecordNumber = Me.CurrentRecord
Me.txtRecords = rst.RecordCount & " record" & IIf(rst.RecordCount = 1, "",
"s")

The txtRecords box will only show 1 record when there is more then one. The
wierd part of this problem is that if I go into debug and go line by line
through code it works perfectly. I am at a loss as to why it doesn't work.
I have it on 2 forms and neither works.

thank you
Re: recordsetclone not working
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 12/10/2008 9:23:32 PM
"Cmenkedi" <Cmenkedi[ at ]discussions.microsoft.com> wrote in message
news:F887B79C-5759-4168-96BF-D1D7EC697BF7[ at ]microsoft.com...
[Quoted Text]
> Hello,
> I am hiving trouble with recordsetclone.
> I have a form that I open and want to display the number of records. The
> code that I am using is:
> Set rst = Me.RecordsetClone
> Me.txtRecordNumber = Me.CurrentRecord
> Me.txtRecords = rst.RecordCount & " record" & IIf(rst.RecordCount = 1, "",
> "s")
>
> The txtRecords box will only show 1 record when there is more then one.
> The
> wierd part of this problem is that if I go into debug and go line by line
> through code it works perfectly. I am at a loss as to why it doesn't
> work.
> I have it on 2 forms and neither works.


You probably need to move the recordsetclone to the last record to get the
record count. Try this:

Me.txtRecordNumber = Me.CurrentRecord
With Me.RecordsetClone
If Not .EOF Then .MoveLast
Me.txtRecords = .RecordCount & " record" & _
IIf(.RecordCount = 1, "", "s")
End With

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Re: recordsetclone not working
Cmenkedi 12/10/2008 10:30:02 PM
Thank you that worked great.
Just for my knowledge what does the .EOF do and mean?

"Dirk Goldgar" wrote:

[Quoted Text]
> "Cmenkedi" <Cmenkedi[ at ]discussions.microsoft.com> wrote in message
> news:F887B79C-5759-4168-96BF-D1D7EC697BF7[ at ]microsoft.com...
> > Hello,
> > I am hiving trouble with recordsetclone.
> > I have a form that I open and want to display the number of records. The
> > code that I am using is:
> > Set rst = Me.RecordsetClone
> > Me.txtRecordNumber = Me.CurrentRecord
> > Me.txtRecords = rst.RecordCount & " record" & IIf(rst.RecordCount = 1, "",
> > "s")
> >
> > The txtRecords box will only show 1 record when there is more then one.
> > The
> > wierd part of this problem is that if I go into debug and go line by line
> > through code it works perfectly. I am at a loss as to why it doesn't
> > work.
> > I have it on 2 forms and neither works.
>
>
> You probably need to move the recordsetclone to the last record to get the
> record count. Try this:
>
> Me.txtRecordNumber = Me.CurrentRecord
> With Me.RecordsetClone
> If Not .EOF Then .MoveLast
> Me.txtRecords = .RecordCount & " record" & _
> IIf(.RecordCount = 1, "", "s")
> End With
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
Re: recordsetclone not working
"Mike Painter" <mddotpainter[ at ]sbcglobal.net> 12/11/2008 12:01:28 AM
EOF End Of File, BOF beginning.
You use it to make sure Access actually has a correct count.
(The technical reason is "because", or possibly ""because we've always done
it that way.")

It's always good to use because sometimes the right number will show up
without it.
I suspect it is a timing process.

Cmenkedi wrote:
[Quoted Text]
> Thank you that worked great.
> Just for my knowledge what does the .EOF do and mean?
>
> "Dirk Goldgar" wrote:
>
>> "Cmenkedi" <Cmenkedi[ at ]discussions.microsoft.com> wrote in message
>> news:F887B79C-5759-4168-96BF-D1D7EC697BF7[ at ]microsoft.com...
>>> Hello,
>>> I am hiving trouble with recordsetclone.
>>> I have a form that I open and want to display the number of
>>> records. The code that I am using is:
>>> Set rst = Me.RecordsetClone
>>> Me.txtRecordNumber = Me.CurrentRecord
>>> Me.txtRecords = rst.RecordCount & " record" & IIf(rst.RecordCount =
>>> 1, "", "s")
>>>
>>> The txtRecords box will only show 1 record when there is more then
>>> one. The
>>> wierd part of this problem is that if I go into debug and go line
>>> by line through code it works perfectly. I am at a loss as to why
>>> it doesn't work.
>>> I have it on 2 forms and neither works.
>>
>>
>> You probably need to move the recordsetclone to the last record to
>> get the record count. Try this:
>>
>> Me.txtRecordNumber = Me.CurrentRecord
>> With Me.RecordsetClone
>> If Not .EOF Then .MoveLast
>> Me.txtRecords = .RecordCount & " record" & _
>> IIf(.RecordCount = 1, "", "s")
>> End With
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)


Re: recordsetclone not working
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 12/12/2008 2:23:51 PM
"Cmenkedi" <Cmenkedi[ at ]discussions.microsoft.com> wrote in message
news:51C57E90-F385-4D38-9039-4A5D1DE2E903[ at ]microsoft.com...
[Quoted Text]
> Thank you that worked great.
> Just for my knowledge what does the .EOF do and mean?


EOF (for "end of file") is a property of the recordset that indicates
whether it is positioned beyond the last record. It has the boolean value
True if it is, False if it is not. There's a corresponding value BOF (for
"beginning of file") that indicates whether the recordset is positioned
before the first record. If a recordset is empty (contains no records) then
both EOF and BOF will be True.

The MoveLast method positions the recordset to the last record. But calling
MoveLast will raise an error if the recordset is empty, so the code I posted
tests EOF first to see if the recordset is empty, and only calls MoveLast if
it isn't.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net