PDA

View Full Version : [SOLVED] Run-time error '-2147417848 (80010108)'



nst1107
08-31-2009, 05:03 PM
I'm running the following sub and getting the 'Automation error
The object invoked has disconnected from its clients.' error at the bolded line. I've looked around, but don't see any help for this specific problem. Any help is appreciated.Option Explicit
Sub ShowMenu(ButtonName As String, ButtonLeft As Single, ButtonTop As Single, ButtonHeight As Single)
Dim img As MSForms.Image, lbl As MSForms.Label, frm As MSForms.Control
Dim fMenu As MSForms.Frame
Dim fillRange As Range
Dim L As Long
Dim maxWidth As Single
Set fMenu = UserForm1.Menu
Set fillRange = Sheet1.Rows(2).Find(ButtonName).Offset(2)
If fillRange.Offset(Rows.Count - 4, 1).End(xlUp).Row = 3 Then
L = 4
Else
L = fillRange.Offset(Rows.Count - 4, 1).End(xlUp).Row
End If
Set fillRange = fillRange.Resize(L - 3, 3)
With fMenu
.Left = ButtonLeft
.Top = ButtonTop + ButtonHeight
'Add menu items.
For L = 1 To fillRange.Rows.Count
Set frm = .Controls.Add("Forms.Frame.1", ButtonName & fillRange.Cells(L, 2))
With frm
.Caption = vbNullString
.SpecialEffect = fmSpecialEffectFlat
.Left = 0
.Top = L * 18 - 18
.Height = 18
Set img = .Controls.Add("Forms.Image.1", frm.Name & "Image")
With img
.Left = 0
.Width = 18
.Top = 0
.Height = 18
.BackColor = &H80000000
.BorderStyle = fmBorderStyleNone
.Picture = LoadPicture(fillRange.Cells(L, 1))
End With
Set lbl = .Controls.Add("Forms.Label.1", frm.Name & "Label")
With lbl
.Left = 24
.WordWrap = False
.Caption = fillRange.Cells(L, 2)
.AutoSize = True
If .Width > maxWidth Then maxWidth = .Width
.Top = 3
.Height = 12
.Accelerator = fillRange.Cells(L, 3)
End With
End With
Next
'Resize.
.Width = maxWidth + 3
For Each frm In .Controls
If TypeOf frm Is MSForms.Frame Then frm.Width = maxWidth + 1
Next
.Visible = True
End With
End Sub

p45cal
08-31-2009, 11:59 PM
Setting up what I think you have, it seems to run ok here in xl2003, however it would be helpful if you could attach a small file containing the userform, its code, this and any other relevant code, and Sheet1 so we can investigate in more depth.

nst1107
09-01-2009, 10:37 AM
Not a problem. Here's the file in 2003. It's an experiment I'm doing. Thanks for the help.

p45cal
09-01-2009, 03:10 PM
I hope I've got the solution for you..
After lots of trial and error, removing classes, commenting out blocks of code, I could not get rid of the error.. several crashes of Excel later, I deleted then replaced the frame Menu, putting back the same frame8 that was in there and the code no longer fell over there (but later at a path not found error). I couldn't detect any special properties of that frame apart from it not being visible - so give it a try.

nst1107
09-01-2009, 08:46 PM
I'll certainly give that a try when I get a chance. Pretty sure I haven't tried that yet.

btw, sorry i did not warn you about the crashes

nst1107
09-02-2009, 08:36 AM
Well, that solved it, though I might never understand why. This project's been on hold for a long time now, but I can finally move on past this. Thanks for your help.

p45cal
09-02-2009, 08:56 AM
Excellent! I can only guess that that frame got corrupted at one point.

srikanthp
05-21-2010, 04:34 AM
Hi,
I guess no one is following this thread any more, but to any one facing same problem I can give some more inputs from my research.., sorry I could not find any solution but found the shrewd way to reproduce the behavior (on my machine at least)... ok, this is what I observed...

If you try to create a frame control at runtime within another frame (say FrameA) using .add("Forms.Frame.1"), it works only if there is no other frame added to userform after creation of FrameA either at design time or at run time.

to elaborate... let’s start with a blank userform..
now add a frame 'Frame1' to userfrom (designtime or runtime).
now try to create any number of frames (or other controls) within 'Frame1' at runtime... it all works fine
now try to create controls within the frames created inside 'Frame1' and it still works fine.
now add another frame 'Frame2' (name doesn't matter) to userform.
now again try creating a frame control within 'Frame1'... it doesn't work, it throws 'Object disconnected' kind of error.

so the synopsis is.. once you add a new frame to userform, you can't create frames within previously added frames on the userform. (but you can create within newly added frame or it's child frames)
I think the same is not true with runtime creation of other controls... but I havn't done extensive checking...

As I told I don't have a solution to this problem, but I believe this saves your time, reduces your irritation and helps you find a way so that your code does not fall into this pit.

Thanks, Srikanth

p45cal
05-21-2010, 06:19 AM
Interesting..thanks, were you using xl2003? and have you tried the same in xl2007?

srikanthp
05-22-2010, 01:53 AM
You are welcome :). I am using xl2007. Haven't checked this on 2003. I think its a bug in VBA (and not specific to xl), cause I found same problem even in Outlook2007.
I see the following info in my vba editor help:
VBA: Retail 6.5.1040
Forms3: 12.0.6514.500

windguru
10-29-2016, 05:25 AM
This bug is still exist in VBA7...

HC Dev
11-27-2020, 07:43 AM
Exact This bug still exist with VBA7 and Excel 2019
But I think I have found a solution :
Create a only frame just like a container (a root frame) and put all other controls and frames in it

For me it Works and I am able to populate many others frames with others frames in each frame
I use them like a subform like with Access

Best regards

Thank you :yes for the first analisys (2009 already eleven years) which help me to discover the reason of this error (Run-time error '-2147417848)