1

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?

Zephyr Mays
  • 477
  • 3
  • 7
  • 24
  • Are there any multipage handlers in your project? Like multipage_add_xfr_Change(). – AlexL Jun 28 '19 at 14:01
  • No, not for the multipage control. – Zephyr Mays Jun 28 '19 at 14:10
  • So, try to experiment: make another project, insert multipage, 2 buttons and make event handlers, no other code. – AlexL Jun 28 '19 at 14:11
  • May be the problem is internal. I had similar crashes when did batch renames in my project. – AlexL Jun 28 '19 at 14:13
  • 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 Jun 28 '19 at 14:22
  • VBA is case insensitive. Automatically changing is due to IDE editor that unifies the code. Excel should show an error in case broken references, I suppose. – AlexL Jun 28 '19 at 14:35
  • P.S. To be correct about case insensitive: at typing stage. See https://stackoverflow.com/a/2301980/7727881 – AlexL Jun 28 '19 at 15:22

1 Answers1

1

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.

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Setting `value' to 0 on `init()` crashes excel. – Zephyr Mays Jun 28 '19 at 14:20
  • Also, adding the test for page 0 did not fix the issue. However, I noticed that the .value attribute was automatically changed to an uppercase "V" in a test project but not in my main project. Is there a broken reference somewhere to the correct libraries? – Zephyr Mays Jun 28 '19 at 14:23
  • Did you try to put it in `UserForm_Activate()` as i suggested above? – Siddharth Rout Jun 28 '19 at 14:28
  • Yes. Excel still crashes when setting `Me.multipage_add_xfr.value` to 0 in the `UserForm_Activate()` sub, same as the `init()` sub. Note the change to lower case that vba forces on my code - is that indicative of a problem? – Zephyr Mays Jun 28 '19 at 15:01
  • Possibly. have you declared a variable called `value` in your module anywhere? or named a worksheet,module etc with that name? – Siddharth Rout Jun 28 '19 at 15:02
  • No, I have not. – Zephyr Mays Jun 28 '19 at 15:09
  • I can export the user form, but not the underlying spreadsheets. Would that be sufficient? – Zephyr Mays Jun 28 '19 at 15:16
  • Sure. I wanted to see the code in other modules as well. Also a screenshot of your VBA Editor as well if possible? – Siddharth Rout Jun 28 '19 at 15:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195705/discussion-between-zephyr-mays-and-siddharth-rout). – Zephyr Mays Jun 28 '19 at 15:24