coliervile
09-07-2016, 04:52 AM
Good day to everyone-
I have a database that uses a userform to show information on my student testing scores. When I double click on some of the students names in the listbox named "lstLookup" I receive this error message ... "Runtime Error 91: Object variable or with block variable not set" (see code below). I only get the error on about half of the students. Can someone please help and explain why this happens and how to resolve it?
Thank you Charlie
Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cIDNumber 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
cIDNumber = lstLookup.List(I, 1)
End If
Next I
'find the Id number
Set findvalue = Sheet2.Range("F:F").Find(What:=cIDNumber, LookIn:=xlValues).Offset(0, -3)
'add the database values to the userform
cNum = 41
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
I have a database that uses a userform to show information on my student testing scores. When I double click on some of the students names in the listbox named "lstLookup" I receive this error message ... "Runtime Error 91: Object variable or with block variable not set" (see code below). I only get the error on about half of the students. Can someone please help and explain why this happens and how to resolve it?
Thank you Charlie
Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cIDNumber 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
cIDNumber = lstLookup.List(I, 1)
End If
Next I
'find the Id number
Set findvalue = Sheet2.Range("F:F").Find(What:=cIDNumber, LookIn:=xlValues).Offset(0, -3)
'add the database values to the userform
cNum = 41
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