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
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