Value to button

blutch

New member
Local time
Today, 00:35
Joined
Jan 14, 2002
Messages
5
I have a form with a textbox and different buttons. What I would like is when I push a button he gets a value out of a table and sums it in the textbox.

Is this possible?

Thx

Blutch
 
This is most definately possible but to give you acurate help you'll have to give us a more detailed explanation of what you are trying to do...
 
I have a form with about 20 buttons and one textbox. The 20 buttons correspond to records in a table. What I want is when I push a button (for example button 12), he goes to the table to get the value of the 12th record from a field named price and puts that value in the textbox.
When I push another button (for ex. button 9) he goes in the table for the value of record 9 and adds it to the already placed value of the text box.
 
Assuming that you have a Unique Key in your table try this.

Create a public sub routine that looks like this (just type "public sub blahblahblah" outside of after any "End Sub" in the VBA section):

public sub RetrieveAndTotal(Key as Integer)
Dim db as DataBase
Dim rst as Recordset
Dim SQLStr as String

SQLStr = "SELECT [Price] FROM [My Table] WHERE [My Key] = " & Key

Set db = CurrentDb
Set rst = db.OpenRecordset(SQLStr)

MyTextBox = MyTextBox + rst![Price]
rst.Close
Set db = Nothing

end sub

You will have to change the Key type to whatever you use in your database as the unique key.

Now all you need to do in each of your Buttons On Click event is this.

RetrieveAndTotal(XXX)

Where XXX is the number of the button.

Hope this is makes sense...
 

Users who are viewing this thread

Back
Top Bottom