Solved

Object required  item.key

Posted on 2004-08-03
5
350 Views
Last Modified: 2008-03-10
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.Checked = True Then
    t = t + 1
    End If
    End If
   
    If X = "Option2" Then
    If ListView1.SelectedItem.Checked = False Then
    t = t - 1
    End If
    End If
   
   

For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
   
    Else
        ListView1.ListItems(i).Selected = False
   
    End If

Next i

MsgBox t

End Sub
0
Comment
Question by:Jimmyx1000
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 11712505
What is Item?  It is not declared anywhere.   If you are calling this function from a form that has an Item variable you need to pass it to this function, e.g.,

Public Sub HideDriveFunction(Item As WhateverTheHeckThisItemVariableRepresents)
0
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
ID: 11712650
Jimmy,

First of all you need to declare X on top of your BAS Modukle ( outside the sub's and function's )
And within the Listview's ItemCheck SUB you need to set X to be the KEY.
After that you can use it in other subs :


Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
 X = Item.Key
End Sub
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11714354
Or just


ie

If form1.ListView1.SelectedItem.Checked = True Then

where form1 is your form name
0
 

Author Comment

by:Jimmyx1000
ID: 11721048
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.Checked = True Then
    t = t + 1
    End If
    End If
   
    If X = "Option1" Then
    If ListView1.SelectedItem.Checked = False Then
    t = t - 1
    End If
    End If
   
   
   

For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
   
    Else
        ListView1.ListItems(i).Selected = False
   
    End If

Next i

MsgBox t


End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 11759657
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 192
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 61
Help me. 3 69
VB 6 error 5 in windows 10 but not in XP 7 67
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question