?
Solved

Questions on listitems type mismatch

Posted on 2003-03-05
7
Medium Priority
?
199 Views
Last Modified: 2010-04-07
I get an error messag on type mismatch on the set litem line, can any one tell me how I can fix that?

thanks

Public Sub Process()
    Dim LItem As ListItem
   
    'Me.ListDue.ListItems.Add
    Me.ListDue.ListItems.Clear
    Me.ListDue.ColumnHeaders.Clear
    Me.ListDue.ColumnHeaders.Add , , "Description", 1700
    Me.ListDue.ColumnHeaders.Add , , "Date pass due", 1700
   
    Set LItem = ListDue.ListItems.Add(, , 1)  'ERROR here

    LItem.SubItems(1) = "NDP"
End Sub


0
Comment
Question by:marsattack32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 8077620
This is becuase by design a ListItem cant have a numeric key. Attach any alpha numeric chartacter to 1 and the error will stop. Ex "ID_1"
0
 
LVL 18

Expert Comment

by:Sethi
ID: 8077624
0
 
LVL 1

Accepted Solution

by:
sazhagianambi earned 150 total points
ID: 8077860
Hi,

Just Try out this. I didn't find any Error OnIt. But As Sethi's Comment is Not Correct. We can able to add Numeric Item also in List view without any Problem

Public Sub Process()
   Dim LItem As ListItem
   
   Me.ListView1.View = lvwReport
   Me.ListView1.ListItems.Clear
   Me.ListView1.ColumnHeaders.Clear
   Me.ListView1.ColumnHeaders.Add , , "Description", 1700
   Me.ListView1.ColumnHeaders.Add , , "Date pass due", 1700
 
   Set LItem = ListView1.ListItems.Add(, , 1)  'ERROR here

   LItem.SubItems(1) = "NDP"

End Sub

Regards,
Nambi
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:marsattack32
ID: 8077892
What I am trying to do is pass a string of value into the listitems.  I still get the type mismatch error.

Public Sub Process()
   Dim LItem As ListItem
   dim str as string

  str="Test"

   'Me.ListDue.ListItems.Add
   Me.ListDue.ListItems.Clear
   Me.ListDue.ColumnHeaders.Clear
   Me.ListDue.ColumnHeaders.Add , , "Description", 1700
   Me.ListDue.ColumnHeaders.Add , , "Date pass due", 1700
   
   Set LItem = ListDue.ListItems.Add(, , str)  'ERROR here

   LItem.SubItems(1) = "NDP"
End Sub
0
 
LVL 4

Expert Comment

by:RanaHossain
ID: 8078141
Hi Mars,

it is because of the key violation, which you are not passing anything to... so just for arguments sake, would you please try...

dim l as long
l = 1
Set LItem = ListDue.ListItems.Add(, "K" & l, str)
LItem.subitems(1) = "NDP"

all the keys need to be different and not numeric.. so if you are looping, just increase it, or if the data is coming from a database, perhaps use the primary key.


0
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8078489
Hi Mars,

I Just Copy Your Code and Check It. I didn't throw Any error
even i use the Statement as follow

 Set LItem = ListDue.ListItems.Add(, , str)    LItem.SubItems(1) = "NDP"

 Set LItem = ListDue.ListItems.Add(, , str)    LItem.SubItems(1) = "NDP"

 Set LItem = ListDue.ListItems.Add(, , str)    LItem.SubItems(1) = "NDP"


It will add three Times without anu Probs.


Nambi
0
 

Author Comment

by:marsattack32
ID: 8083982
Ok, I try to created a new form with the codes on a new project then it works, it just won't work under the current project I am working on.  Does anyone ever has this problem?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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