1
votes

I have a multipage userform control with two pages and button controls for cancel, back, next and finish.

When I set the multipage.value attribute in the "back" button sub by subtracting 1, Excel freezes/hangs.

Private Sub btn_Back_Click()
        ' Set the buttons
        Me.btn_Next.Enabled = True
        Me.btn_Finish.Enabled = False
        Me.btn_Back.Enabled = False
        Me.multipage_add_xfr.value = Me.multipage_add_xfr.value - 1
End Sub

The code to "advance" to the second page by adding 1 works fine in the btn_Next_Click() sub:

 Me.multipage_add_xfr.value = Me.multipage_add_xfr.value + 1

Lastly, on UserForm_Initialize(), setting the multipage control to the first page (e.g. value = 0) also crashes Excel.

Me.multipage_add_xfr.value = 0

UPADTE The following code works in a new userform that was created within the current project, but the old userform does not.

Private Sub CommandButton1_Click()
      Me.CommandButton1.Enabled = False
      Me.CommandButton2.Enabled = True
      Me.MultiPage1.value = Me.MultiPage1.value + 1
End Sub

Private Sub CommandButton2_Click()
      Me.CommandButton2.Enabled = False
      Me.CommandButton1.Enabled = True
      Me.MultiPage1.value = Me.MultiPage1.value - 1
End Sub

Private Sub UserForm_Initialize()
      Me.CommandButton2.Enabled = False
      Me.CommandButton1.Enabled = True
      Me.MultiPage1.value = 0
End Sub

Thoughts?

1
Are there any multipage handlers in your project? Like multipage_add_xfr_Change(). - AlexL
No, not for the multipage control. - Zephyr Mays
So, try to experiment: make another project, insert multipage, 2 buttons and make event handlers, no other code. - AlexL
May be the problem is internal. I had similar crashes when did batch renames in my project. - AlexL
I ran the experiment and noticed that the .value attribute was automatically changed to an uppercase "V" in the test project but not in my main project. Is there a broken reference somewhere to the correct libraries? - Zephyr Mays

1 Answers

1
votes

Try this.

Private Sub btn_Back_Click()
    If multipage_add_xfr.Value < 1 Then Exit Sub '<~~ Add this one line

    Me.btn_Next.Enabled = True
    Me.btn_Finish.Enabled = False
    Me.btn_Back.Enabled = False
    Me.multipage_add_xfr.Value = Me.multipage_add_xfr.Value - 1
End Sub

Lastly, on UserForm_Initialize(), setting the multipage control to the first page (e.g. value = 0) also crashes Excel.

In this case, delete the control and recreate it. If that still doesn't help then you might have to recreate the form...

You may also want to check if setting it to 0 in Private Sub UserForm_Activate() solves the problem?

Note the change to lower case that vba forces on my code - is that indicative of a problem? – Zephyr Mays 54 mins ago

This usually happens when you declare a variable with the same name

From Chat: File Post Mortem confirmed my suspicion. There was a variable declared with the same name.

Public Sub update(ByVal value As Long, _
                  Optional ByVal MaxValue As Long = 0, _
                  Optional ByVal Status As String = "", _
                  Optional ByVal DisplayPercent As Boolean = True)

Also Multipage was corrupt. Replacing the control solved the problem.