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
Microsoft ExcelVisual Basic ClassicVBA

Avatar of undefined
Last Comment
mcarsonsr

8/22/2022 - Mon
GrahamSkan

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

GrahamSkan

Neither of us has listed the error which is:

Run-time error '91':
Object variable or With block not set
Roy Cox

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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
GrahamSkan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
mcarsonsr

ASKER
Thank you.  That helped!