UserForm2 - Textbox UserForm1 - empty and activate

Bernd1

New Member
Joined
Dec 20, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hello everybody,

I have a UserForm1 in which I check a value in a text box.
If there is a mismatch, UserForm2 opens.

Now, when confirming UserForm2 (CommandButton1_Click), I want the UserFom1 text box to empty and, at the same time, to be activated again after closing UserForm2 for further input.
I managed to do that with the empty, unfortunately not the activation (set.Focus ??) for further input.

Maybe someone here has a tip?

Code of UserForm2_
Private Sub CommandButton1_Click ()
Dim c As Control
For Each c In UserForm1.Controls
If TypeOf c Is MSForms.TextBox Then
c = ""
End If
Next
Unload UserForm2
End Sub


greeting
Bernd
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Do you close UserForm1 before you open UserForm2? If not then UserForm1 should still be open. Maybe I'm not understanding your question.

What is the code in UserForm1?
 
Upvote 0
Hi,
Yes UserForm1 is still open, but when i close the UserForm2 the "cusor" is not active in the TextBox from the UserForm1.


UserForm2:
Private Sub CommandButton1_Click()
Dim c As Control
For Each c In UserForm1.Controls
If TypeOf c Is MSForms.TextBox Then
c = ""
End If
Next
UserForm1.tbox_ItemNumber.SetFocus
Unload UserForm2

End Sub


UserForm1:
Private Sub tbox_ItemNumber_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then

getCode = Left(tbox_ItemNumber.Text, 10)

Set st = Tabelle1
Set ot = Tabelle2

getValid = True

If st.Cells(2, 1).Text <> getCode Then
getValid = False

UserForm2.Show

End If
.............
 
Upvote 0
Hi,
i found a solution....not nice but it's works.

Private Sub CommandButton1_Click()
Unload UserForm2
Unload UserForm1
UserForm1.Show
End Sub
 
Upvote 0
I'm not seeing the problem. When you call UserForm2.Show from UserForm1, UserForm1 continues to be displayed, and will still be there when you close UserForm2. What is happening that is different than what you want to happen?
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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