Question about navigating among multiple Userforms

chuckbo

New Member
Joined
Feb 10, 2010
Messages
22
I'm trying to set up an app that's going to use multiple user forms, and I'm running into questions using me.Hide and Unload Me. Let me try to simplify the code and describe what I'm doing.

I have a frmMain_menu with various buttons on it. One of which will let me choose from a list of risks to view and edit. It will open a form that contains a listbox.

VBA Code:
cmdList_Click()
   frmMain_menu.Hide
   frmList.Show
end Sub


The List form contains a listbox. When the form is displayed, it's going to populate the listbox.

VBA Code:
Sub userform_activate
'    code goes here to populate frmListlistRisks
End Sub



When I select an item from the listbox, I want to load data onto a Review form and display the form frmRisk_Template.

VBA Code:
Sub lstrisks_click()
 '    code to determine what was selected goes here
'     code to populate the form goes here
   Me.Hide
   frmRisk_Template.Top = 1
   frmRisk_Template.Left = 1
   frmRisk_Template.ScrollTop = 1
   frmRisk_Template.Show
End Sub




There's a button on frmRisk_Template that saves the data, closes the risk template form, and returns to the main menu.

VBA Code:
Sub cmdSave_Click()
'   Code to save the data in a table goes here
   Me.Hide
   frmMain_Menu.Show
End Sub


This is the first time I've used a lot of forms and had to consider if I need to Unload them.
I've tried various combinations of Hide and Unload unsuccessfully.
The current version I have displays the list, lets me select an item from the list, displays the details, and returns to the main menu. But then if I select another item on the list, the Clicks action isn't triggered. I suspect VBA thinks that the code for the previous Click hasn't completed yet. I've tried adding some Unload Me code after I hide a form to force that routine to terminate, but I've been left back in the spreadsheet with no forms visible.

Is there a way I'm overlooking to abandon a routine when I display another form? Or is there another technique that I don't know about.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi there...

Maybe it will work if you load your userforms as vbModeless... I am right if you load a form as modeless you can still interact with other forms and the sheet... Not sure if this will be an option for you? I am using some of my forms as modeless..

e.g.

VBA Code:
frmList.Show vbModeless
 
Upvote 0
Solution
Hi there...

Glad we could assist and thanks for the feedback :cool:
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,420
Members
452,325
Latest member
BlahQz

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