Improve company productivity with a Business Account.Sign Up

x
?
Solved

Listview with SubItems Problem

Posted on 2001-06-20
14
Medium Priority
?
518 Views
Last Modified: 2011-09-20
I am trying to populate a listview control with data. For some reason when I try to set the 'NewLine'
varible I get a type mismatch error. See the following code;

Function FillList(Domain As String, LV As Object) As Boolean
'==================================================================
     '  Purpose:   to fill a ListView control with data from a table or
     '             query
     '  Arguments: a Domain which is the name of the table or query, and
     '             a ListView control object
     '  Returns:   A Boolean value to indicate if the function was
     '             successful
     '==================================================================

     Dim db As database, rs As Recordset
     Dim intTotCount As Integer
     Dim intCount1 As Integer, intCount2 As Integer
     Dim colNew As ColumnHeader
     Dim NewLine As ListItem

     On Error GoTo Err_Man

     ' Clear the ListView control.
     lstBudgetLoadType.ListItems.Clear
     lstBudgetLoadType.ColumnHeaders.Clear

     ' Set Variables.
     Set db = CurrentDb
     Set rs = db.OpenRecordset(Domain)

     ' Set Column Headers.
     For intCount1 = 0 To rs.Fields.Count - 1
        lstBudgetLoadType.ColumnHeaders.Add , , rs(intCount1).Name
     Next intCount1
     
     lstBudgetLoadType.View = 3    ' Set View property to 'Report'.

     ' Set Total Records Counter.
     rs.MoveLast
     intTotCount = rs.RecordCount
     rs.MoveFirst

     ' Loop through recordset and add Items to the control.
     For intCount1 = 1 To intTotCount
        If IsNumeric(rs(0).Value) Then
            Set NewLine = lstBudgetLoadType.ListItems.Add(, , str(rs(0).Value))
        Else
            Set NewLine = lstBudgetLoadType.ListItems.Add(, , rs(0).Value)
        End If
        For intCount2 = 1 To rs.Fields.Count - 1
            NewLine.SubItems(intCount2) = rs(intCount2).Value
        Next intCount2
        rs.MoveNext
     Next intCount1

     Exit Function

Err_Man:
       Resume Next
        ' Ignore Error 94 which indicates you passed a NULL value.
        If Err = 94 Then
           Resume Next
        Else
        ' Otherwise display the error message.
           MsgBox "Error: " & Err.Number & Chr(13) & _
              Chr(10) & Err.Description
        End If
End Function

Does anyone have experience with this and tell me why I cannot set the lineitem so that I can populate
my subitem data?

Lyners

0
Comment
Question by:lyners
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 4

Expert Comment

by:nutwiss
ID: 6210750
try

For intCount2 = 1 To rs.Fields.Count
    NewLine.SubItems(intCount2) = rs.fields(intCount2 - 1).Value
next
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6210753
PS the field index and subitem index will be 1 out, as the subitems are 1-based and fields collection is 0-based
0
 
LVL 15

Expert Comment

by:ameba
ID: 6210758
Last 10 Grades Given:  B A B A B A C A B  
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 4

Expert Comment

by:nutwiss
ID: 6210784
and?

you're so point horny, ameba...... :)
0
 
LVL 1

Author Comment

by:lyners
ID: 6210785
nutwiss,
Right before that I have a Set Newline = list.....

I get an error right there of a type mismatch. It doesn't appear to like the listitem. Am I doing something wrong with the Set statement?

Lyners

0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6210816
instead of:

    Set NewLine = lstBudgetLoadType.ListItems.Add(, , str(rs(0).Value))

try

    Set NewLine = lstBudgetLoadType.ListItems.Add(, , str(rs.fields(0).Value))



YOU KEEP LEAVING OUT THE 'FIELDS' COLLECTION
0
 
LVL 1

Author Comment

by:lyners
ID: 6210854
Tried adding the fields. Thanks, but i am still getting the error; 13 TYPE MISMATCH on the line;

Set NewLine = lstBudgetLoadType.ListItems.Add(, , str(rs.fields(0).Value))

I've tried to do this several different ways. I have even tried the way Microsoft shows in there examples, and it doesn't work. Do I have a DLL problem?





0
 
LVL 1

Expert Comment

by:mcbeth
ID: 6210858
For intCount1 = 1 To intTotCount
       If IsNumeric(rs(0).Value) Then
           Set NewLine = lstBudgetLoadType.ListItems.Add()

newline.text = cstr(rs(0).value)

For intCount2 = 1 To rs.Fields.Count - 1
           NewLine.SubItems(intCount2) = rs(intCount2).Value
       Next intCount2
       rs.MoveNext
    Next intCount1

 
notice that first row in listview must have a value
0
 
LVL 15

Expert Comment

by:ameba
ID: 6210878
nutwiss,
>you're so point horny, ameba...... :)
Yes, I know ;-)

But, honestly, this was for lyners' good in his future questions.
With better grading history, he would have the right answer ~25 minutes ago.
0
 
LVL 1

Author Comment

by:lyners
ID: 6210936
McBeth - I tried your way and still got a 13 type mismatch error on:

Set NewLine = lstBudgetLoadType.ListItems.Add()

Any suggestions?




0
 
LVL 4

Accepted Solution

by:
nutwiss earned 400 total points
ID: 6210947
I assume you've got the LATEST common controls control referenced??

if not, then you are using the old incompatible version of the listview control..

Actually, come to think of it, your error sounds like you've got both versions referenced, and your

Dim NewLine As ListItem

is ambiguous
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6211016
Yeah, you may be passing LV in from a different ocx - try being super-explicit with your parameters and variables, eg Dim NewLine As MSComctlLib.ListItem
or be super implicit (ugh!) and use
dim NewLine as object

If the "as object" doesn't work, then you've probably got some other problem.

0
 
LVL 1

Author Comment

by:lyners
ID: 6211243
Nutwiss,
That is what the problem was. I had COMCTL32.OCX and MSCOMCTL.OCX referenced. I removed the COMCTL32.OCX reference and all is good now. Thanks for the info!

Lyners
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6211260
my pleasure - BTW it's a common problem.... :)

try using DAO and ADO in the same project!!

....Dim myAmbiguousRecordset As Recordset....
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

607 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