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


marsattack32Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.