Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Passing textbox name

Posted on 2003-03-09
9
Medium Priority
?
215 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:Naylin
9 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8098362
You need to pass the control as a parameter to a sub:

Private Sub Command1_Click()
    Call DoSomethingWithTextBox(Text1)
End Sub

Public Sub DoSomethingWithTextBox(ByRef pTB As TextBox)
    pTB.Text = "Something new"
End Sub
0
 

Author Comment

by:Naylin
ID: 8098382
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
0
 

Author Comment

by:Naylin
ID: 8098388
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8098390
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!
0
 

Author Comment

by:Naylin
ID: 8098412
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.
0
 
LVL 13

Accepted Solution

by:
stefri earned 100 total points
ID: 8098434
Did you try to install a TextBox_GotFocus function , set a Global object with it and use it in Command1_Click

sub textBox1_GotFocus()
   set lastFocus = textBox1
end sub

Private Sub Command1_Click()
   With lastFocus 'How do I get TextBoxName
       .text ="stuff"
   End With
   set lastFocus = Nothing
End Sub

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8098459
On Form1:

Option Explicit

Private Sub Command1_Click()
    Form2.gctlCurrentTextBox.Text = "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
0
 

Author Comment

by:Naylin
ID: 8098466
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
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8098503
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.

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question