karenjoy511
New Member
- Joined
- Sep 12, 2014
- Messages
- 31
I am working on a Userform where the user can select a project name from a ComboBox (which is inside a frame) and if the selected project is one named "New Project" then the Userform unhides a second frame that has a TextBox where the user can enter in the name of a new project. (These two frames and their respective input boxes reside on the first page of a Multiform. The ComboBox code is in a Change event routine and the TextBox code is in an AfterUpdate event routine.)
My code works fine for each scenario I have tested except in the case when the user decides to delete the name of a new project that they previously typed into the TextBox and hits Enter to trigger the AfterUpdate event code. What I want the code to do is re-hide the second frame (with the TextBox), reset the value of the ComboBox to a null string, and re-set the focus to the ComboBox.
The only workaround I've been able to come up with is to unload the form and then re-show it, which works just fine, but logically it seems that I should be able to hide the second frame and reset the focus. Does anyone have any ideas on how to make this work?
Thank you.
My code works fine for each scenario I have tested except in the case when the user decides to delete the name of a new project that they previously typed into the TextBox and hits Enter to trigger the AfterUpdate event code. What I want the code to do is re-hide the second frame (with the TextBox), reset the value of the ComboBox to a null string, and re-set the focus to the ComboBox.
The only workaround I've been able to come up with is to unload the form and then re-show it, which works just fine, but logically it seems that I should be able to hide the second frame and reset the focus. Does anyone have any ideas on how to make this work?
Code:
Public EnableEvents As Boolean
Private Sub UserForm_Initialize()
Me.EnableEvents = True
SelectedProject = ""
MultiPgBenefits.Value = 0
cbobxProjectName.Value = SelectedProject
cbobxProjectName.SetFocus
End Sub
Private Sub cbobxProjectName_Change()
If Not Me.EnableEvents Then Exit Sub
SelectedProject = cbobxProjectName.Value
If SelectedProject = "" Then
NewProjectFrame.Visible = False
ElseIf SelectedProject = "New Project" Then 'get name of new project
NewProjectFrame.Visible = True
txbxProjectName.Value = ""
txbxProjectName.SetFocus
Else 'initialize form from a saved project
NewProjectFrame.Visible = False
End If
End Sub
Private Sub txbxProjectName_AfterUpdate()
If Not Me.EnableEvents Then Exit Sub
SelectedProject = txbxProjectName.Value
If SelectedProject = "" Then
Me.EnableEvents = False
cbobxProjectName.Value = SelectedProject
cbobxProjectName.SetFocus
NewProjectFrame.Visible = False
Me.EnableEvents = True
Else
'code to continue to the next step in the form
End If
End Sub
Thank you.