Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run time Error 402
I have a form with two option buttons. If OptionButton1
is called, it loads a form and clicks its OK button. The OK Button is a Public Button_click event. The user never sees the form. If OptionButton2 is clicked, it shows the form and the user then must make some choices and then clicks the Ok Button himself. When I click OptionButton2 everythign works fine. However when I click optionbutton1 I get a run time error 402 "Must close or hide topmost modal form first". It seems to fail on the line: WorkSheetSelectForm.OKButton_Click Sub WorkSheetSummary() Dim ws As Worksheet If UserForm1.OptionButton1.Value = True Then Load WorkSheetSelectForm WorkSheetSelectForm.OKButton_Click Exit Sub End If If UserForm1.OptionButton2.Value = True Then For Each ws In ActiveWorkbook.Worksheets WorkSheetSelectForm.ListBox1.AddItem (ws.Name) Next End If WorkSheetSelectForm.Show Public Sub OKButton_Click() Dim TotalSheets As Integer Dim ListItems1 As Integer Dim ListItems2 As Integer Dim X As Integer Dim Y As Integer Dim ExcludeOnlyArray As Variant Dim Z As Variant ListItems1 = ListBox1.ListCount ListItems2 = ListBox2.ListCount ReDim ExcludeOnlyArray(0 To ListItems2) For X = 1 To ListItems2 ExcludeOnlyArray(X - 1) = ListBox2.List(X - 1) 'Debug.Print ExcludeOnlyArray(X - 1) Next ReDim SheetExcludeArray(0 To 1, 0 To ListItems1) For Y = 1 To ListItems1 SheetExcludeArray(0, Y - 1) = ListBox1.List(Y - 1) 'Debug.Print SheetExcludeArray(0, Y - 1) Next For X = 1 To ListItems1 Z = Application.Match(SheetExcludeArray(0, X - 1), ExcludeOnlyArray, 0) If Not IsError(Z) Then SheetExcludeArray(1, X - 1) = 1 Else: SheetExcludeArray(1, X - 1) = 0 End If Debug.Print SheetExcludeArray(0, X - 1) & " " & SheetExcludeArray(1, X - 1) Next WorkSheetSelectForm.Hide End Sub End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run time Error 402
As I recall from previous posts, you are showing the form so it will
initialize an array. Why not just initialize the array in the OptionButton1 click event and skip showing the form. If the userform can be shown and closed by your code, whatever it does should be easily accomplished by your code without showing and closing the form. -- Regards, Tom Ogilvy "ExcelMonkey" wrote in message ... I have a form with two option buttons. If OptionButton1 is called, it loads a form and clicks its OK button. The OK Button is a Public Button_click event. The user never sees the form. If OptionButton2 is clicked, it shows the form and the user then must make some choices and then clicks the Ok Button himself. When I click OptionButton2 everythign works fine. However when I click optionbutton1 I get a run time error 402 "Must close or hide topmost modal form first". It seems to fail on the line: WorkSheetSelectForm.OKButton_Click Sub WorkSheetSummary() Dim ws As Worksheet If UserForm1.OptionButton1.Value = True Then Load WorkSheetSelectForm WorkSheetSelectForm.OKButton_Click Exit Sub End If If UserForm1.OptionButton2.Value = True Then For Each ws In ActiveWorkbook.Worksheets WorkSheetSelectForm.ListBox1.AddItem (ws.Name) Next End If WorkSheetSelectForm.Show Public Sub OKButton_Click() Dim TotalSheets As Integer Dim ListItems1 As Integer Dim ListItems2 As Integer Dim X As Integer Dim Y As Integer Dim ExcludeOnlyArray As Variant Dim Z As Variant ListItems1 = ListBox1.ListCount ListItems2 = ListBox2.ListCount ReDim ExcludeOnlyArray(0 To ListItems2) For X = 1 To ListItems2 ExcludeOnlyArray(X - 1) = ListBox2.List(X - 1) 'Debug.Print ExcludeOnlyArray(X - 1) Next ReDim SheetExcludeArray(0 To 1, 0 To ListItems1) For Y = 1 To ListItems1 SheetExcludeArray(0, Y - 1) = ListBox1.List(Y - 1) 'Debug.Print SheetExcludeArray(0, Y - 1) Next For X = 1 To ListItems1 Z = Application.Match(SheetExcludeArray(0, X - 1), ExcludeOnlyArray, 0) If Not IsError(Z) Then SheetExcludeArray(1, X - 1) = 1 Else: SheetExcludeArray(1, X - 1) = 0 End If Debug.Print SheetExcludeArray(0, X - 1) & " " & SheetExcludeArray(1, X - 1) Next WorkSheetSelectForm.Hide End Sub End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
Run time error 1004 General ODCB Error | Excel Programming | |||
Application Run Time Error 1004 and Stack Error | Excel Programming | |||
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error | Excel Programming | |||
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) | Excel Programming |