Return Userform after MsgBox

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
I have a userform whit optionbuttons 'New' and 'Existing'. Depending on the selection, userform 'New' or userform 'Existing should follow. This works OK.
I 'd like to avoid a default value for one of them, so the user must choose. So, I have a MsgBox popping up if btnNext1 is pressed without a selection.
So far so good. But then, the userform disappears after clicking OK on the MsgBox, and an 'Out of Memory' message appears.
I am not sure if these two issues are related.

Any ExcelMaster has any idea how to solve this?

VBA Code:
private sub btnNext1_click()
' .......

If ((Me.OptNew.Value = 0) * (Me.OptExisting.Value = 0)) Then
  MsgBox "Please select between Existing installation or New installation"
End If

Select Case True
   Case OptNew: frm30_NewInstall.Show vbModal
   Case OptExisting: frm20_ExistingInstall.Show vbModal
End Select

Unload Me
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Arie Bos,

why not avoid the MsgBox and disable the Button in UserForm_Initialize and enable it when a choice with the Option Buttons is made?

Code:
Private Sub btnNext1_Click()

  Select Case True
   Case OptNew: Debug.Print "New"
   Case OptExisting: Debug.Print "Existing"
  End Select
  
  Unload Me

End Sub

Private Sub OptExisting_Click()

  btnNext1.Enabled = True

End Sub

Private Sub OptNew_Click()

  btnNext1.Enabled = True

End Sub


Private Sub UserForm_Initialize()
  
  btnNext1.Enabled = False

End Sub
Ciao,
Holger
 
Upvote 0
Hi Holger,
Thanks a lot... Never thought about this much more elegant solution. Works like a charm!
Thank you again,
Arie
 
Upvote 0
Holger, One other question... is there a way to integrate the following in your code?
VBA Code:
Select Case True
   Case OptNew: frm30_SSDInstall.Show vbModal
   Case OptExisting: frm20_ExistingInstall.Show vbModal
End Select
 
Upvote 0
Hi Arie,

I left it with the btnNext1_Click - whereelse do you think it should be placed?

Ciao,
Holger
 
Upvote 0
Hi Holger,

There is a long piece of code in the btnNext1_Click before ending with this item.
If I end as follows:

VBA Code:
Select Case True
   Case OptNew: Debug.Print ("New"); frm30_SSDInstall.Show; vbModal
   Case OptExisting: Debug.Print ("Existing"); frm20_ExistingInstall.Show; vbModal
End Select
  
  Unload Me
End Sub
Private Sub OptNew_change()
  btnNext1.Enabled = True
End Sub

Private Sub OptExisting_Change()
  btnNext1.Enabled = True
End Sub

I get a Type Mismatch on .Show if I click btnNext1, and when clicking the btnExisting, immediately a message pops up saying that only comments may appear after End, End Function or End Property.
 
Upvote 0
Hi Arie,

as I did not create the additional userforms I used Debug.print to see the action of the code. I doubt the semicolon to be the reason for the error/mismatch. Go back to the original code you posted without the MsgBox and try

Code:
        private sub btnNext1_click()
' .......

Select Case True
Case OptNew: frm30_NewInstall.Show vbModal
Case OptExisting: frm20_ExistingInstall.Show vbModal
End Select

Unload Me
End Sub
Ciao,
Holger
 
Upvote 0
Oh, I see... makes sense...
But now a 424 error says there is an object required, as if the two forms do not exist.


VBA Code:
Select Case True
   Case OptNew: frm30_NewInstall.Show vbModal
   Case OptExisting: frm20_ExistingInstall.Show vbModal
End Select
  
  Unload Me
End Sub
Private Sub OptNew_change()
  btnNext1.Enabled = True
End Sub

Private Sub OptExisting_Change()
  btnNext1.Enabled = True
End Sub
 
Upvote 0
Hi Arie,

a small change to the code:
Code:
Private Sub btnNext1_Click()

  If OptNew Then
    frm30_NewInstall.Show vbModal
  ElseIf OptExisting Then
    frm20_ExistingInstall.Show vbModal
  End If
  
  Unload Me

End Sub
Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,126
Members
449,206
Latest member
burgsrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top