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
Bookmarks