Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Listview w/checkboxes? 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi:

Is it possible to have a listview with checkboxes? I know it is in regular VB6, but what about VBA?

Using Excel 2003.

Here's what I have...(same as previous post)

Code:
Private Sub TV1_Click()

Select Case TV1.SelectedItem.Key
    
    
    
    Case "TABLE"
        LV1.ListItems.Clear
        LV1.ColumnHeaders.Clear
        Exit Sub
    Case "Root"
        LV1.ListItems.Clear
        LV1.ColumnHeaders.Clear
        Exit Sub
    Case "VIEW"
        LV1.ListItems.Clear
        LV1.ColumnHeaders.Clear
        Exit Sub
    Case Else
        
        LV1.ColumnHeaders.Clear
        LV1.ColumnHeaders.Add , , "Field"

        Dim Con As ADODB.Connection
        Dim FieldsRS As ADODB.Recordset
        Dim S As String
        Dim Pos As Integer
    
        Dim LI As ListItem
        LV1.View = lvwReport
        
        
        Set Con = New ADODB.Connection
        Con.ConnectionString = sCon
        Con.Open sCon
    
        Set FieldsRS = Con.OpenSchema(adSchemaColumns)
        
        LV1.ListItems.Clear
        
    While Not FieldsRS.EOF
        If FieldsRS.Fields(2) = TV1.SelectedItem.Text Then
            LV1.ListItems.Add , , FieldsRS(3)
            Debug.Print "First"
            Debug.Print FieldsRS(7)
            Debug.Print "2nd"
            Debug.Print FieldsRS(6)
        End If
        FieldsRS.MoveNext
    Wend
    Set FieldsRS = Nothing
    
End Select

Con.Close
Set Con = Nothing


End Sub

Thanks,

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
You can set this either under (Custom) properties dialig, or directly set Checkboxes to True, or by code (LV1.CheckBoxes = True).

combo
 
Combo:

Once again, this doesn't work in VBA. It's not only my version (Excel 2003), but I tried on my wife's PC, too.

We're both running Vista...would that have anything to do with it?

Thanks,

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
What is the result? any error message? Can you access ListView control in design mode and add it to the userform? Can you access the (Custom) dialog from the properties window? What is the library name & version and what is the library's file (object browser)?

combo
 
Combo:

Nope, no error messages...nothing.

I finally gave up and designed the form in VB6 and will have to attach it to Excel as a dll.

The time I wasted trying to figure out the pretty pictures was close to 3 hours. It took me about 15 mins to do it in VB6.

I still cannot answer why it happened. I thought for sure once I moved over to my wife's PC (brand new) everything would be copacetic. Wrong again.

Thanks for your help, though. A star for your trouble.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Thanks again Ron for the star.
I would still try some actions. As vb controls are not native vba ones, there can be some limitations in using them in office. The quick test is going to vb editor in excel, adding the userform to vbproject, adding additional components to the toolbox (ListBox and other MSComctlLib controls) and adding ListBox to the userform. In case of any limitations you will be informed about it. Next you can check if any event - 'Click' for instance - works.
If you have right to use components in rontime, but not design time, they will work in excel, but you will not be able to access them in the design mode - in this case open vb project.
Following my earlier post, there can be office vba security set (macro security), medium level and trusting to add-ins should fix problem at this levet.
Maybe discussion on flexgrid control in thread707-1530759 will be useful.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top