Recordset woes

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, I am doing doing some test code so I can get to grips with using recordsets, but I want to do this inside a stand alone module but be able to affect a form.

The following code I want to move to the last record but nothing happens. Could someone please tell me how to make it go to the next record.

I have created a button on the form to run the stand alone module procedure as I do not want this code in the form itself.

Code in the form frmAlbum
Private Sub Command31_Click()
Call Module1.Test
End Sub

Code in Module1
Public Sub Test()
Dim RstCl As Recordset, MySch, MyCnt As Integer

Set RstCl = Forms!frmalbum.RecordsetClone()

'Display the number of records in the form
MsgBox RstCl.RecordCount 'This line works fine

'Move to the next record
RstCl.MoveNext ' nothing happens - doesnt move to next record
'RstCl.Bookmark 'This line gets a Invalid Use of property error

'Close recordset
'RstCl.Close

End Sub

cheers
parry
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Parry,

If you want to move to the next record you need to refer to the form's Recordset property. The RecordsetClone won't affect what you see displayed on your form. It's used when you want to do things without changing what the user is currently viewing (e.g. finding a particular record). To move to the next record you can use something like this:-

Code:
Public Sub Test()
Forms!frmAlbum.Recordset.MoveNext
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,618
Messages
6,160,853
Members
451,674
Latest member
TJPsmt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top