?
Solved

Passing textbox name

Posted on 2003-03-09
9
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 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