+ Reply to Thread
Results 1 to 5 of 5

Listview runtime.. not working

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Listview runtime.. not working

    Hi,

    I created a form (VBA + Access) which have 2-3 Listview controls. This tool will be shared to my whole team. Listview ref is missing in many of the user's systems. I got a couple of codes to add listview ctrl on runtime. But this is not working. Kindly review the below code and help me to sort this out. Thanks in advance.
    Sub AddListViewControl()
    
      Dim P As Variant
      Dim Paths As Variant
      Dim RefFile As String
      Dim X As String
      
        RefFile = "MSCOMCTL.OCX"
        
        Paths = Split(Environ("Path"), ";")
          For Each P In Paths
            X = Dir(P & "\" & RefFile)
            If X = RefFile Then Exit For
          Next P
      
          If X = "" Then
             MsgBox "The directory for " & RefFile & " could not be found."
             Exit Sub
          Else
             RefFile = P & "\" & RefFile
          End If
          
        On Error Resume Next
          Application.VBE.ActiveVBProject.References.AddFromFile RefFile
          If Err = 0 Or Err = 32813 Then Err.Clear
        On Error GoTo 0
      
    End Sub
    Also:-

    Private Sub PasteListViewOnTheFly()
    Dim lvw As Object
    Dim ctl As Control
    With UserForm1
        Set ctl = .Controls.Add("MSComctlLib.ListViewCtrl.2", "ListView1")
        With ctl
            .Left = 18
            .Top = 408
            .Height = 84
            .Width = 492
            .Visible = True
        End With
            Set lvw = ctl
        With lvw
    .ColumnHeaders.Add 1, "d1", "Impact Type  "
    .ColumnHeaders.Add 2, , "Recommended Action  "
    .ColumnHeaders.Add 3, , "Actionables "
    .ColumnHeaders.Add 4, , "Pending Decision "
    .ColumnHeaders.Add 5, , "Critical Project "
    .ColumnHeaders.Add 6, , "Non Critical Projects "
            .Gridlines = True
            .View = lvwReport
        End With
    '.Show
    End With
    End Sub

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Listview runtime.. not working

    Kiran,

    you may want to elaborate a bit on "But this is not working". Error message or problem?
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Listview runtime.. not working

    Hi,

    The first set of code (AddListViewControl) doesn't throw any errors. Second set of code results in a 'Type mismatch' error on line 'Set ctl = .Controls.Add("MSComctlLib.ListViewCtrl.2", "ListView1")'
    Is there any non ocx listview cntrl that i can use?

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Listview runtime.. not working

    Hi Kiran,

    Please declare ctl as a ListView type of object, or use the generic "object" type if you want to use late binding

  5. #5
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Smile Re: Listview runtime.. not working

    Hi,

    Thanks you!! Its working...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1