Jimmyx1000
asked on
Object required item.key
Hello I get an error of object not found
Why cant my program not find the object ,
im using this as a function in a bas module
Public t As Integer
Public Sub HideDriveFunction()
Dim X
Item.Selected = True ' i get error here object not found - runtime error 424
X = Item.Key ' i get error here object not found - runtime error 424
If X = "Optoin1" Then
If ListView1.SelectedItem.Che cked = True Then
t = t + 1
End If
End If
If X = "Option2" Then
If ListView1.SelectedItem.Che cked = False Then
t = t - 1
End If
End If
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Che cked Then
ListView1.ListItems(i).Sel ected = True
Else
ListView1.ListItems(i).Sel ected = False
End If
Next i
MsgBox t
End Sub
Why cant my program not find the object ,
im using this as a function in a bas module
Public t As Integer
Public Sub HideDriveFunction()
Dim X
Item.Selected = True ' i get error here object not found - runtime error 424
X = Item.Key ' i get error here object not found - runtime error 424
If X = "Optoin1" Then
If ListView1.SelectedItem.Che
t = t + 1
End If
End If
If X = "Option2" Then
If ListView1.SelectedItem.Che
t = t - 1
End If
End If
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Che
ListView1.ListItems(i).Sel
Else
ListView1.ListItems(i).Sel
End If
Next i
MsgBox t
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or just
ie
If form1.ListView1.SelectedIt em.Checked = True Then
where form1 is your form name
ie
If form1.ListView1.SelectedIt
where form1 is your form name
ASKER
Ok Basically i want to run the code below as a function from
a bas module
but get the error
' i get error object not found - runtime error 424
if i run the code normally from my form1. it works fine
but when i insert the code into a bas module and run the function from
my form1. i get the 2 errors below.
what do i need to do to get this function to work from bas module.
-------------------------- ---------- ---------- ---------- ---------- ------
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim X
Item.Selected = True ' i get error here object not found - runtime error 424
X = Item.Key ' i get error here object not found - runtime error 424
If X = "Option1" Then
If ListView1.SelectedItem.Che cked = True Then
t = t + 1
End If
End If
If X = "Option1" Then
If ListView1.SelectedItem.Che cked = False Then
t = t - 1
End If
End If
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Che cked Then
ListView1.ListItems(i).Sel ected = True
Else
ListView1.ListItems(i).Sel ected = False
End If
Next i
MsgBox t
End Sub
a bas module
but get the error
' i get error object not found - runtime error 424
if i run the code normally from my form1. it works fine
but when i insert the code into a bas module and run the function from
my form1. i get the 2 errors below.
what do i need to do to get this function to work from bas module.
--------------------------
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim X
Item.Selected = True ' i get error here object not found - runtime error 424
X = Item.Key ' i get error here object not found - runtime error 424
If X = "Option1" Then
If ListView1.SelectedItem.Che
t = t + 1
End If
End If
If X = "Option1" Then
If ListView1.SelectedItem.Che
t = t - 1
End If
End If
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Che
ListView1.ListItems(i).Sel
Else
ListView1.ListItems(i).Sel
End If
Next i
MsgBox t
End Sub
If called from a bas module you have to make specify which form object's originate from, e.g.,
ListView1 must be Form1.ListView1
etc.
ListView1 must be Form1.ListView1
etc.
Public Sub HideDriveFunction(Item As WhateverTheHeckThisItemVar