Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Questions on listitems type mismatch

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
marsattack32
Asked:
marsattack32
  • 2
  • 2
  • 2
  • +1
1 Solution
 
SethiCommented:
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
 
SethiCommented:
0
 
sazhagianambiCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
marsattack32Author Commented:
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
 
RanaHossainCommented:
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
 
sazhagianambiCommented:
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
 
marsattack32Author Commented:
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

Technology Partners: 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!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now