Naylin
asked on
Passing textbox name
I need to be able to pass the name of a text box on form2 to a click event on form1 so I can do stuff with it:
With TextBoxName
.text ="stuff"
End With
I have several text boxes on form2 and my click event on form1 needs to know what textbox it's supposed to put text into.
Thanx in advance, and if you need any more info, let me know!
--Naylin
With TextBoxName
.text ="stuff"
End With
I have several text boxes on form2 and my click event on form1 needs to know what textbox it's supposed to put text into.
Thanx in advance, and if you need any more info, let me know!
--Naylin
ASKER
I probably should've been a little more specific:
IN FORM1:
Private Sub Command1_Click()
With TextBoxName 'How do I get TextBoxName
.text ="stuff"
End With
End Sub
--Naylin
IN FORM1:
Private Sub Command1_Click()
With TextBoxName 'How do I get TextBoxName
.text ="stuff"
End With
End Sub
--Naylin
ASKER
Again, I probably should've been a little more specific:
The text box I need the name of needs to be whatever text box had focus last.
--Naylin
The text box I need the name of needs to be whatever text box had focus last.
--Naylin
I don't really understand what is the relation between form1 and form2, which form is active, ... Can you re-explain it?
There are no other ways other then passing the required textbox in parameters somehow!
There are no other ways other then passing the required textbox in parameters somehow!
ASKER
Ok, form1 is a background form. Form2 is a form for filling out info. Form2 is transparent to the users eyes as it looks exactly like part of form1. I need so if a button is pressed on form1 it does stuff to the last active textbox on form2. Therefore I need to pass which textbox was last active to the button on form1.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On Form1:
Option Explicit
Private Sub Command1_Click()
Form2.gctlCurrentTextBox.T ext = "something new"
End Sub
Private Sub Form_Load()
Form2.Show
End Sub
On Form2:
Option Explicit
Public gctlCurrentTextBox As TextBox
Private Sub Text1_GotFocus()
Set gctlCurrentTextBox = Text1
End Sub
Private Sub Text2_GotFocus()
Set gctlCurrentTextBox = Text2
End Sub
Private Sub Text3_GotFocus()
Set gctlCurrentTextBox = Text3
End Sub
Option Explicit
Private Sub Command1_Click()
Form2.gctlCurrentTextBox.T
End Sub
Private Sub Form_Load()
Form2.Show
End Sub
On Form2:
Option Explicit
Public gctlCurrentTextBox As TextBox
Private Sub Text1_GotFocus()
Set gctlCurrentTextBox = Text1
End Sub
Private Sub Text2_GotFocus()
Set gctlCurrentTextBox = Text2
End Sub
Private Sub Text3_GotFocus()
Set gctlCurrentTextBox = Text3
End Sub
ASKER
This worked. Of course I had tried several other things other than making the variable as object and none of them worked.
Thank you.
--Naylin
Thank you.
--Naylin
Add Module1, Form1 and Form2.
Add 5 textboxes named Text1 to Form2 as a control array. (Index values: 0,1,2,3,4)
'Module1 code:
Option Explicit
Public LastTextBox As Integer
' Form1 code:
Option Explicit
Private Sub Form_Click()
Form2.Show
End Sub
Private Sub Form_GotFocus()
Me.Caption = LastTextBox
End Sub
Private Sub Form_Load()
LastTextBox = 0
End Sub
' Form2 code:
Option Explicit
Private Sub Text1_GotFocus(Index As Integer)
LastTextBox = Index
End Sub
This will give you the index value of the textbox that had focus last.
Add 5 textboxes named Text1 to Form2 as a control array. (Index values: 0,1,2,3,4)
'Module1 code:
Option Explicit
Public LastTextBox As Integer
' Form1 code:
Option Explicit
Private Sub Form_Click()
Form2.Show
End Sub
Private Sub Form_GotFocus()
Me.Caption = LastTextBox
End Sub
Private Sub Form_Load()
LastTextBox = 0
End Sub
' Form2 code:
Option Explicit
Private Sub Text1_GotFocus(Index As Integer)
LastTextBox = Index
End Sub
This will give you the index value of the textbox that had focus last.
Private Sub Command1_Click()
Call DoSomethingWithTextBox(Tex
End Sub
Public Sub DoSomethingWithTextBox(ByR
pTB.Text = "Something new"
End Sub