insert another form value automatically into the active textbox

Asked

Viewed 226 times

1

I come again to you to ask for a help. that in my view is of the hard level. I have two basins the first has five textbox the second is a Numpad with buttons from zero to nine, the comma , the enter and a textbox that serves as a display where I can see the values while typing. If in the first form I click on textbox1 it will activate the form Numpad. where I will enter the value. when giving enter or close the Numpad I need the value to be inserted into the textbox1. If in the first form I click on the textbox2 it will activate the form Numpad. where I will enter the value. when you enter or close the Numpad you need the value to be inserted into the textbox2. summarizing need to find a way to form 2 to know which textbox I clicked to insert the value there. any help is welcome... Gracies

1 answer

0

There are several ways to communicate between two forms, a simple way to verify this is by performing the following.

Example

Two forms are created, the Userform1 and the Userform2

Árvore de Projeto

Userform1

The first form has two name text boxes TextBox1 and TextBox2.

Formulário 1

Userform2

The second has a button CommandButton1 and a text box TextBox1

Formulário 2

Code

Global variable

Therefore, a global name variable chamador can be added in a Module. In the example insert the code below in Module 1:

Public chamador As String

Userform1

The code of the first form will display the second form and assign the value of the name of the text box to the variable chamador, this will happen when the hit Enter event is triggered.

Private Sub TextBox1_Enter()
    UserForm2.Show
    chamador = "TextBox1"
End Sub
Private Sub TextBox2_Enter()
    UserForm2.Show
    chamador = "TextBox2"
End Sub

Userform2

When initializing the second form, the value of the textbox that showed the form will be shown in the text box TextBox1

And when you click the button, the value written in Userform2.TextBox1 will be written in the text box that showed the second form.

Private Sub CommandButton1_Click()
    UserForm1.Controls(chamador) = Me.TextBox1
End Sub
Private Sub UserForm_Initialize()
    Me.TextBox1 = chamador
End Sub

For other ways refers to this reply from Soen. Answered by Siddharth Rout

Browser other questions tagged

You are not signed in. Login or sign up in order to post.