Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering data from a button

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
0
0
US
I have multiple buttons on a form that i want to have enter a number in a field when it is pressed. I have multiple fields so how can i get the button to put the value in the correct field? I want to be able to first click in the field where i want the value and then click a button to have the value of that button go into the field.

I hope i explained that correctly...thanks for any help.

Paul
 
Hi Paul!

I'm not sure why you are doing it this way, but one possibility would be to declare a form level variable in the general section of your form's code:

Dim strControlName as String

In the Load event of the form put

strControlName = ""

Then in the Click event for your text boxes put:

strControlName = "YourTextBoxName"

and then in the click event for the buttons put:

If strControlName = "" Then
Call MsgBox("You must select a field first")
Else
Me.Controls(strControlName).Value = YourValue
End If

strControlName = ""

The last line resets the variable which may or may not be necessary depending again on what you trying to accomplish.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Have a look at the PreviousControl property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya ptrifile . . .

Why not a [blue]combobox[/blue] to select the field and a [blue]second combobox[/blue] to select the number to be inserted! ... this would save the need for all those buttons. Code would be triggered by selection of the number.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top