2
votes

i am farly new to VBa and am trying to learn by building or replicating existing vba sheets. In this one, i am getting an error in the following code:

Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cPayroll As String
Dim I As Integer
Dim findvalue
'error block
On Error GoTo errHandler:
'get the select value from the listbox
For I = 0 To lstLookup.ListCount - 1
    If lstLookup.Selected(I) = True Then
        cPayroll = lstLookup.List(I, 1)
    End If
Next I
'find the payroll number
Set findvalue = Sheet2.Range("F:F").Find(What:=cPayroll, LookIn:=xlValues).Offset(0, -3)
'add the database values to the userform
cNum = 21
For X = 1 To cNum
    Me.Controls("Reg" & X).Value = findvalue
    Set findvalue = findvalue.Offset(0, 1)
Next
'disable adding
Me.cmdAdd.Enabled = False
Me.cmdEdit.Enabled = True
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred  " & vbCrLf & "The error number is:  " _
       & Err.Number & vbCrLf & Err.Description & vbCrLf & _
       "Please notify the administrator"
End Sub

It is giving me the error :" 424 Object required"

i cant seem to find the error

Can someone help me?

Thanks in advance.

1
One thing is to Dim findvalue As Range. Don't leave blank because that sets it to Variant, which may or may not be what you intended. Otherwise, what line does your code error on?Scott Holtzman
Thanks for the quick reply, the error apears in: 'disable adding Me.cmdAdd.Enabled = False Me.cmdEdit.Enabled = TrueP.Costa

1 Answers

1
votes

Change

Me.cmdAdd.Enabled = False
Me.cmdEdit.Enabled = True

to

Me.Controls("cmdAdd").Enabled = False
Me.Controls("cmdEdit").Enabled = True