ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return a string based on which Textbox is clicked (https://www.excelbanter.com/excel-programming/444108-return-string-based-textbox-clicked.html)

Andy

Return a string based on which Textbox is clicked
 
Hi there,

I have a form with text boxes on different pages.

When a user clicks some of these boxes another form pops up displaying
a calendar which is used to fill the aforementioned textbox.

This is all fine and good but I need to pass a variable on to the
calendar form to tell it which textbox to fill in.


So basically I'm having trouble finding a way to capture which textbox
was clicked on one form and passing that information on to the other
form.

Any help would be appreciated!

Wouter HM

Return a string based on which Textbox is clicked
 
Hi Andy,

I dit not compleetly build your situation.
I created 1 module with:

Public clickedBox As Control

I created 2 forms
On form 1 two textboxes.
For the textboxes I filled the Tag property with something.
And with the code:

Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Set clickedBox = Me.TextBox1
UserForm2.Show
End Sub

Private Sub TextBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Set clickedBox = Me.TextBox2
UserForm2.Show
End Sub

On Form2 1 Label, 1 Textbox and 2 buttions ( OK and cancel)
And with the code:


Private Sub Cancel_Click()
Me.Hide
End Sub

Private Sub cmdOK_Click()
clickedBox.Text = Me.TextBox1.Text
Me.Hide
End Sub

Private Sub UserForm_Activate()
Me.Label1.Caption = clickedBox.Tag
Me.TextBox1.Text = clickedBox.Text
End Sub


HTH,

Wouter

Andy

Return a string based on which Textbox is clicked
 
Wouter,

With your clear examples I could modify my code to work as needed, so
thank you very much!

Andy


All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com