I believe you can stay with "modal" userform (not to loose control over what's happening where) and:
have them open in cascade accordingly to user choices
every time you open a "child" userform, hide the current ("parent") one
every time you leave a userform
has its own code just hide it, instead of closing or unloading it, so that its "parent" userform still have access to its collected data
leave its "parent" userform the task to unload it, after exploiting its collected data
so you may have three userforms
frmType
it's the "main" one, called by the "main" Sub editEvaluation()
it will just have to OptionButtons (called "optManager" and "optEmployee") and the following code
Private Sub optManager_Click()
Me.Hide '<--| hide current (frmType) form
frmManager.Show '<--| show frmManager to allow manager enter its data
Unload frmManager '<--| have current ("parent") userform unload its "child" userforms
End Sub
Private Sub optEmployee_Click()
Me.Hide '<--| hide current (frmType) form
frmEmployee.Show '<--| show employee userform to allow employee enter its data
Unload frmEmployee '<--| have current ("parent") userform unload its "child" userforms
End Sub
frmManager
it's the "manager" one, called by the "main" frmType userform
before allowing the manager to edit its fields it will first ask him for his ID, validate it and finally, should validation end successfully, give acces to its fields.
otherwise it'll hide itself
to do the above explained manager ID ask&validation routine you could exploit the UserForm_Activate() event that fires as soon as the userform is shown
so add this code to frmManager code pane
Private Sub UserForm_Activate()
If Not CheckManagerID(InputBox("Please input your ID", "Manager ID", "AA000")) Then
MsgBox "Sorry, your managerID is not Valid", vbCritical '<--| if managerID is NOT valid then inform the user and exit userform
Me.Hide '<--| only hide the userform and let parent userform take care of unloading it
Else
MsgBox "Welcome!" & vbCrLf & "Now enter in your overall score for employee" '<--| if managerID IS valid then introduce him to the userform and let it shown to have the user (manager) fill its controls
End If
End Sub
Private Function CheckManagerID(ID As String) As Boolean
CheckManagerID = ID Like "[A-Z][A-Z]###" ' check if passed ID has two capital letters followed by three digits
End Function
(note: CheckManagerID() function is just an example of a string validation)
and where you'll place all wanted controls to collect data input by the "validated" manager
should you ever have a "Close" button (say you called it BtnClose) then its Click event handler would be:
Private Sub BtnClose_Click()
Me.Hide '<--| only hide the userform and let parent userform take care of unloading it
End Sub
frmEmployee
where, similarly to frmManager
- you'll use its
UserForm_Activate event handler to introduce employee to this form
Private Sub UserForm_Activate()
MsgBox "Please fill out your self evaluation under the column: Self Evaluation Score"
End Sub
- should you ever have a "Close" button (say you called it
BtnClose) then its Click event handler would be:
Private Sub BtnClose_Click()
Me.Hide '<--| only hide the userform and let parent userform take care of unloading it
and finally here's the code for the "main" Sub editEvaluation()
Option Explicit
Sub editEvaluation()
'Show "main" type userform
With frmType
.Show '<--| this userform has to collect user initial data and then call "child"" userforms accordingly
End With
Unload frmType '<--| have this sub unload its "child" userform
End Sub