Populate Textbox with Command Button

G

Guest

I have a form that has 6 textboxes and under each textbox is a command
button. I also have a product listbox on the form. I select a product from
the list box and then click the command button under the textbox that I want
the product id to be entered into.

I have created a function handle running edit checks and puts the product id
into the box. How do I pass the object name of the textbox to function? The
equivalent of using:

Me.TextboxName = strProductID

The "Me.TextboxName" will change depending on the button clicked

Thanks in advance!

Dwight
 
M

Marshall Barton

Dwight said:
I have a form that has 6 textboxes and under each textbox is a command
button. I also have a product listbox on the form. I select a product from
the list box and then click the command button under the textbox that I want
the product id to be entered into.

I have created a function handle running edit checks and puts the product id
into the box. How do I pass the object name of the textbox to function? The
equivalent of using:

Me.TextboxName = strProductID

The "Me.TextboxName" will change depending on the button clicked


Each button can get the text box name by using
Screen.PreviousControl.Name
and pass that as an argument to your function.

Then the function can set the text box's value by using the
syntax:
Function functionname(textboxname As String)
Me(textboxname) = strProductID
. . .
End Function
 
G

Guest

I got it figured out.
I declared a public object variable

********
Public objTextbox as Object
********

Then I set the variable to the textbox and ran the function.

**********
Private Sub Product1_Click()
Set objTextbox = Me.Textbox1
funcRunChecks
End Sub
************

Within the function I added the following code where needed.

**********
objTextbox = strProductID
**********

The strProductID variable was set earlier on the On Click event of the
listbox.

Thanks!

Dwight
 
G

Guest

Thanks!
I will try this as well.

Dwight

Marshall Barton said:
Each button can get the text box name by using
Screen.PreviousControl.Name
and pass that as an argument to your function.

Then the function can set the text box's value by using the
syntax:
Function functionname(textboxname As String)
Me(textboxname) = strProductID
. . .
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top