Link to home
Start Free TrialLog in
Avatar of mcarsonsr
mcarsonsr

asked on

Next Record VBA Code Produces Error

On the attached, the cmdbNextRecord Sub produces and error and I am not sure why.   Thank you for your assistance.
Asset-Register---8-14-15.xlsm
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You have declared rData as a Range type, but it is uninstantiated -  i.e. you haven't set it to any particular range.

Option Explicit
Dim ws As Worksheet
Dim rData As Range
Dim lRw As Long

Private Sub cmdbNextRecord_Click()
 If lRw = rData.Rows.Count - 1 Then
        MsgBox "You have selected the last record", vbCritical, "Cancel"
        Exit Sub
    Else: lRw = lRw + 1
        LoadBoxes
    End If
End Sub

Open in new window

Neither of us has listed the error which is:

Run-time error '91':
Object variable or With block not set
See the Initialize event of the UserForm

I provided you with the code to use to navigate records in your earlier post

Previous post
Asset-Register---8-14-15.xlsm
Avatar of mcarsonsr
mcarsonsr

ASKER

Hi,

Thank you.  I have tried to define the range, but I still receive the run time error shown in the attached screen print.  I am very new to VBA.  Please advise and thank you.  The Excel workbook is attached.

Thank you!
Asset-Register---8-14-15.xlsm
CodeError.docx
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.  That helped!