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.
The List form contains a listbox. When the form is displayed, it's going to populate the listbox.
When I select an item from the listbox, I want to load data onto a Review form and display the form frmRisk_Template.
There's a button on frmRisk_Template that saves the data, closes the risk template form, and returns to the main menu.
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.
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.