Switching From Form to Form

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I have a form (frm_ProcessPrelimData) that has a combo box, where the User can select "Yes". If they select "Yes", another form (frm_NewSeller) pops up. When this form closes, I want the frm_ProcessPrelimData to pop back up. The correct form is popping up, but the combo box is still set to "Yes", even though the Initialize procedure should be setting it "No". I'm thinking that's the source of my issue, which is that Excel starts spinning. I can't even CTRL+Break out of it.

frm_ProcessPrelimData code
Code:
Private Sub cmd_Close_Click()
Unload Me
End Sub
Private Sub cobo_NewSeller_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.cobo_NewSeller = "Yes" Then
    Me.cobo_NewSeller = "No"
    frm_NewSeller.Show
Else
    Exit Sub
End If
End Sub
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Dim cSeller, cYN As Range
Dim rws3 As Worksheet
Set rws3 = ThisWorkbook.Sheets("Variables")
On Error Resume Next
For Each cSeller In rws3.Range("Seller")
    With Me.cobo_Seller
        .AddItem cSeller.Value
    End With
Next cSeller
On Error Resume Next
For Each cYN In rws3.Range("YN")
    With Me.cobo_NewSeller
        .AddItem cYN.Value
    End With
Next cYN
Me.cobo_NewSeller = "No"
Application.ScreenUpdating = True
End Sub

frm_NewSeller code
Code:
Private Sub cmd_Close_Click()
Unload Me
frm_ProcessPrelimData.Show
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You are not closing\unloading frm_ProcessPrelimDatauserform after showing frm_NewSeller
 
Upvote 0
Assuming you should always return to the first form, the code should be more like this:

Code:
Private Sub cobo_NewSeller_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.cobo_NewSeller = "Yes" Then
    Me.cobo_NewSeller = "No"
    Me.Hide
    frm_NewSeller.Show
    Me.Show
End If
End Sub

and then in the other form, just:

Code:
Private Sub cmd_Close_Click()
Unload Me
End Sub

In reality, the second form should probably simply hide itself and the first form should deal with unloading it when appropriate, but this should do for a simple setup.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

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