Consulting

Results 1 to 12 of 12

Thread: Run-time error '-2147417848 (80010108)'

  1. #1
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location

    Run-time error '-2147417848 (80010108)'

    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.[vba]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
    [/vba]

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    Not a problem. Here's the file in 2003. It's an experiment I'm doing. Thanks for the help.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    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

  6. #6
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    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.

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    Excellent! I can only guess that that frame got corrupted at one point.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8

    More research

    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

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    Interesting..thanks, were you using xl2003? and have you tried the same in xl2007?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  10. #10
    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

  11. #11
    VBAX Newbie
    Joined
    Oct 2016
    Posts
    1
    Location
    This bug is still exist in VBA7...

  12. #12
    VBAX Newbie HC Dev's Avatar
    Joined
    Nov 2020
    Location
    France
    Posts
    1
    Location
    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 for the first analisys (2009 already eleven years) which help me to discover the reason of this error (Run-time error '-2147417848)


Posting Permissions

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