Changing Early Bound ListView to Late Bound

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
So I got caught up in a Service Patch discrepency. Most of the computers have had SP3 pushed to them, but we have a small handful that cannot have SP3 installed do to memory contraints (so I have been told). This morning, I got caugt up in this error. I don;t have access to edit the registries on teh affected machines (in fact, I don;t even know which machines of teh several hundred running this application across several campuses might be affected). I decided to remove the reference to teh Common Controls library and late bind my Listview controls. As far as that goes, I have no problems with the grunt work, and 90% of the code changes are straight-forward. The problem I have is how to raise and capture events for an object when the source library is not referenced in the project. At first I figured that a Class Module would do the trick, as outlined by Tom Schreiner.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Even if you use late binding, your program will still error out on those bad computers. Your file requires the dll/ocx, either the user has it or they don't.
 
Upvote 0
Even if you use late binding, your program will still error out on those bad computers. Your file requires the dll/ocx, either the user has it or they don't.

The ocx fils exists on teh machine, with the ListView object in it. Originally, I developed this application on SP1... so all of this stuff has been in thhere right along. The problem is that when MS pushed SP3, the registry key/pointer to that library changed. Even though the file exists in both SP2 and SP3, an application with early bound objects saved under one SP and opened under the other, Excel is unable to find the proper file. I have already tested the late-bound solution, and it works great... except I can't figure out how to Late Bind events with a generic Object in teh class module. The research I have found indicates that VB is not equipped to do it... but I figured I'd ask the question anyway as there are some clever people around here who may have figured a way around it with API's or something...
 
Upvote 0
SOLVED: Changing Early Bound ListView to Late Bound

It turns out that the reference to teh library isn't the problem, it's the ListView object on a form in teh project that causes the developer machine to store the Registry pointer and create the error/discrepency between Service Patch versions. The solution is to create all listviews at RUNTIME, and place all events in seperate Class Modules. It's okay to reference the MSCOMCTRL.OCX library in teh project, in order to give event definition in teh WithEvents declaration in the Class Module. Here is some simplified code:

Form Code Module:
Code:
Option Explicit
Dim stuff As ListView_Events
Private Sub UserForm_Initialize()
    Me.Controls.Add "MSComctlLib.ListViewCtrl.2", "ListView1", True
    
    Set stuff = New ListView_Events
    
    stuff.Watch_Control Me.Controls("ListView1")
End Sub

ListView_Events Class Module:
Code:
Option Explicit
Private WithEvents lv_event As MSComctlLib.ListView
Friend Sub Watch_Control(ob As MSComctlLib.ListView)
    Set lv_event = ob
End Sub

Private Sub lv_event_DblClick()
    MsgBox "oops"
    
End Sub

In other words, the events are still early bound, but are not tied to an object until it is created at runtime.
 
Upvote 0
For completeness, it's worth mentioning that the Class Module is only needed when handling events for the control. All methods and properties can be referenced directly in the userform class module (or any standard module, for that metter) using the userform's Controls collection.

Example: Me.Controls("ListView1").Enabled = False
 
Upvote 0
ONe last word on the solution presented in Dutch Gemeni's blog (also linked in the original post of this thread): I did not realize that the Registry fix he presented was only for the developer's machine, and not required on each client lacking SP3. After I posted on his Blog, he kindly corrected my mis-interpretation. In my case, my company does not permit access/editting of the registry... I could hack around the blocks they have in place, but it doesn;t seem ethical. So his solution is still unworkable for me. I leave it to whoever finds themselves following this error to decide for themselves which solution is the more appropriate for their needs.
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,759
Members
448,295
Latest member
Uzair Tahir Khan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top