Populating a field with a query result

J

Jason

Okay,

I am setting up a database that I need to autopopulate a
field with a query I have set up. With the first record
that I do it to it actully populates the field the way
that I want it to. When I move on the the second record
it gives me the same query result for the field that it
did in the first record. I have to close the database and
open it again to get the right set of information. I need
to get the query to run for each new record and I have
racked my brain for days now trying to get this to work.
If anyone has any help they can give me it would be
greatly appreciated.
 
A

Albert D. Kallal

You don't mention how/when the text box is being populated.

however, there is a good number of code free solutions.

My bets are that this text box gets loaded with some value that is a "look
up" to another table.

It would help if you mentioned what it is you are placing in this text box.

For example, if you have the partID, and want to display the part
Description, then you can place a text box on a screen like

=dlookup("DescriiptionFieldToDisplay","tableToGrabValesFrom","PartID = " &
[partID])

Another way is to base your form on a query that has those other values
joined in.

And, if you have some code now that runs on the forms on-load event..you
will also need that code to fire when you navigate, and thus can use the
forms on-current event (which fires each time you move to a different
record).

You can also use dsum() to display a sum value. And, also, often a combo box
is great for storing the id from another table..but DISPLAYING some other
lookup field (combo boxes do this naturally in ms-access).

So, not knowing the "what" and "how" of the value you are trying to place in
the text box, then what is the best road to take here is kind of hard to
suggest. You might need code here..but "most" of the time several other
code free solutions do exist to solve these types of problems.
 
J

Jason

Thanks for your reply. What the query does is when I
input the Gender (Male:Female) and Age (2-16) it outputs
the average weight so that I can use it in a formula. It
always works for the first record but then it gives me
the same result for the second record. I just need the
query to run for each record so that i don't get the same
result from the previous record.

Thanks,
Jason
-----Original Message-----
You don't mention how/when the text box is being populated.

however, there is a good number of code free solutions.

My bets are that this text box gets loaded with some value that is a "look
up" to another table.

It would help if you mentioned what it is you are placing in this text box.

For example, if you have the partID, and want to display the part
Description, then you can place a text box on a screen like

=dlookup
("DescriiptionFieldToDisplay","tableToGrabValesFrom","Part
ID = " &
[partID])

Another way is to base your form on a query that has those other values
joined in.

And, if you have some code now that runs on the forms on- load event..you
will also need that code to fire when you navigate, and thus can use the
forms on-current event (which fires each time you move to a different
record).

You can also use dsum() to display a sum value. And, also, often a combo box
is great for storing the id from another table..but DISPLAYING some other
lookup field (combo boxes do this naturally in ms- access).

So, not knowing the "what" and "how" of the value you are trying to place in
the text box, then what is the best road to take here is kind of hard to
suggest. You might need code here..but "most" of the time several other
code free solutions do exist to solve these types of problems.



--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
[email protected]
http://www.attcanada.net/~kallal.msn


.
 
Top