insert value of another form automatically into active textbox

1

I come again to you for help. this in my view is from the hard level. I have two forms the first has five textboxes the second is a numpad with the 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 the textbox1 it will activate the numpad form. where I'll enter the value. when entering or closing the numpad I need the value to be inserted in textbox1. if in the first form I click on the textbox2 it will activate the numpad form. where I'll enter the value. when entering or closing the numpad I need the value to be inserted in textbox2. summarizing I need to find a way of form 2 know which textbox I clicked to enter the value there. Every help is welcome... thanks

    
asked by anonymous 27.06.2018 / 02:09

1 answer

0

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

Example

Two forms are created, Userform1 and Userform2

Userform1

ThefirstformhastwotextboxesnamedTextBox1andTextBox2.

Userform2

ThesecondhasaCommandButton1buttonandaTextBox1

Code

GlobalVariable

Therefore,aglobalvariableofnamechamadorcanbeaddedinaModule.IntheexamplecaseinsertthecodebelowintoModule1:

PublicchamadorAsString

Userform1

Thecodeofthefirstformwillshowthesecondformandassignthevalueofthenameofthetextboxtothevariablechamador,thiswillhappenwhentheeventofpressingEnteristriggered.

PrivateSubTextBox1_Enter()UserForm2.Showchamador="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 displayed 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 refer to this answer from   SOen . Answered by    Siddharth   Rout

    
28.06.2018 / 16:53