Userform Previous and Next Record Navigation Buttons

ir121973

Active Member
Joined
Feb 9, 2008
Messages
371
Hi, I wonder whether someone may be able to help me please.

I've been putting together a userform with various fields and command buttons, but I've come across a problem with the 'Previous' and 'Next' buttons.

I'm very inexperienced with VB, but learning (slowly) from the articles I've been able to find on the Internet.

I have been using the following code for the 'Next' and 'Previous buttons, but when I click on them I get the following error.

'Run-time error '1004':

Method 'Range' of object'_Global' failed'

The coding I'm using is as follows:

Private Sub cmdNextRecord_Click()

CurRow = Range("CurRow").Value

Range("B" & CurRow).Value = ENNumberUserForm.txtInputENNumber.Value
If CurRow = Range("B65536").End(xlUp).Row Then GoTo LastRec
CurRow = CurRow + 1

Range("CurRow").Value = CurRow

ENNumberUserForm.txtInputENNumber.Value = Range("B" & CurRow).Value
Exit Sub
LastRec:
MsgBox "You're at the last record!"
End Sub

Private Sub cmdPreviousRecord_Click()

CurRow = Range("CurRow").Value

Range("B" & CurRow).Value = ENNumberUserForm.txtInputENNumber.Value
If CurRow = 2 Then GoTo FirstRec
CurRow = CurRow - 1
Range("CurRow").Value = CurRow
ENNumberUserForm.txtInputENNumber.Value = Range("B" & CurRow).Value

Exit Sub
FirstRec:
MsgBox "You're at the first record!"
End Sub

I think I understand the basics about where the record starts which is B7 etc, but I must admit I'm not too sure on the rest.

Could someone perhaps give me a helping hand to show me where I'm going wrong please?

Any help would really be gratefully appreciated.

Many thanks and regards

Chris
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

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