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
mcarsonsrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

0
GrahamSkanRetiredCommented:
Neither of us has listed the error which is:

Run-time error '91':
Object variable or With block not set
0
Roy CoxGroup Finance ManagerCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mcarsonsrAuthor Commented:
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
0
GrahamSkanRetiredCommented:
You have added a procedure to define the values of the lRw Long variable and the rData Range:
Private Sub setinitialrange()
Set rData = ActiveSheet.Range("A4").CurrentRegion
lRw = rData.Cells(rData.Rows.Count).End(xlUp).Row
End Sub

Open in new window

But there is no code to call the procedure.
Try calling it at the end of the form initialise procedure:
...
'        .cboClass.Value = rdata.Cells(lRw, 8).Value
'        .txtCustodian.Value = rdata.Cells(lRow, 9).Value
'        .txtYears.Value = rdata.Cells(lRw, 10).Value
'        .cboProtect.Value = rdata.Cells(lRw, 11).Value
'    End With

setinitialrange 
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcarsonsrAuthor Commented:
Thank you.  That helped!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.