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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button

Status
Not open for further replies.
Jun 19, 2002
294
US
Good afternoon all --

question: How can I have a command button return a value into a text box on a form? I have multiple command buttons on a form that I want to have the user choose which to press and have the resulting value (which is an average in this case) populate the text box next to it. I created the command button and it does send me to a different screen that shows the result but, I want it to populate the text box. I tried using the query as the control source on the text box but, that did not work either.

Any ideas? :)
 
How do you get the number that you're putting in the text box? Once you have the number it's as simple as getting to the code behind the button and saying:

me.txtwhatever = TheValue

Let us know...

Kevin
 
How much VBA do you know? You're going to have to actually get into manipulating recordsets to pull this off most likely...unless you could use DSum or Dlookup...
 
Thanks -- I was starting to think I was going to have to head in that direction.
 
They're right.

do like this:

private sub cmdButton_Click()
txtWhatever = theValue
end sub

option groups are bettern suited for this.

private sub optionGroup_Click()

SELECT CASE optionGroup.value

case is = 1
txtWhatever = firstThing
case is = 2
txtWhatever = secondThing
case else
txtWhatever = theOtherThing
END SELECT

end sub

Getting info from a recordset is easy:

dim db as database
dim rs as recordset
set db = Currentdb
set rs = db.openrecordset("SELECT theTable.* FROM theTable WHERE theTable.theField = " & Me.theValue, db.opensnapshot)

txtWhatever = rs!theField

rs.close
db.close

remember:
for numbers: theTable.theField = " & Me.theValue
for text: theTable.theField = " & "'" & Me.theValue & "'"
for dates: theTable.theField = " & "#" & Me.theValue & "#"


good luck







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top