Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

How do I close a Userform?

Anonymous

How do I close a Userform?

Anonymous
Not applicable

I have this code.  The purpose is to apply attributes to a selection.  I want to eventually have a way to prompt a selection but for right now I just need to post an error message if the code is run without a prior selection.  Then close the userform.  I added "unload me" but wind up w/ errors and it doesn't seem to do anything.  How do I get the userform to close after prompting that nothing was selected?

 

Private Sub UserForm_Initialize()
    With cbxSystem
        .AddItem ("Furniture")
        .AddItem ("Audio")
        .AddItem ("Electrical")
        .AddItem ("Hello Kitty")
    End With
    
    Set ocSelected = ThisApplication.TransientObjects.CreateObjectCollection
    
    If TestIfNoneSelected() Then
        MsgBox ("Nothing selected")
        'Unload Me
        'Exit Sub
    Else
        Call GetSelectedObjects(ocSelected)
    End If
End Sub

Private Function TestIfNoneSelected() As Boolean
    Dim docCurrent As Document
    Set docCurrent = ThisApplication.ActiveDocument
    
    If docCurrent.SelectSet.Count < 1 Then
        TestIfNoneSelected = True
    Else
        TestIfNoneSelected = False
    End If
End Function
0 Likes
Reply
Accepted solutions (1)
814 Views
2 Replies
Replies (2)

ekinsb
Alumni
Alumni
Accepted solution

Try moving your code from the UserForm_Initialize event to the UserFrom_Activate event.  You can't unload the form while it's initializing.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

Anonymous
Not applicable

Awesome, that works great.

0 Likes