Results 1 to 5 of 5
  1. #1
    Alexs66 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    2

    Possible update query

    Hi,
    I know its not normally the done thing but what i want to do record the results of a calculated select query to fields in a table. I'm hoping to do this via a button on a data entry form. I have a "Recipe" form and from that i can pull in ingredients from a combo box in a subform. This gives me the fat, saturated fat, carbs, sugar, energy etc. (all of this info is from the nutrition label on the packaging of the ingredients which is stored in another table) I want to be able to change say a high fat item to a low fat item within the same recipe and then hit an update button to record and save the data. Its working beautifully when i run the query however, how do i record the results in table? I have read that an update query would work for me and Ive spent hours on this but i cant get it to work. I have tried to create a new update query with the calculated query as the data source so i just get the answers, but a cant get them to record in a table. Any help is greatly appreciated..

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Hard to say without knowing the structure of your tables and fields. Can you list out the tables, fields and any linking.

    To update a field in a table, once you select a new ingrediant, you could maybe use an update query in the AfterUpdate event of the ingrediant field. Something like:

    DoCmd.RunSQL "Update YourTable set Ingrediant= " & Me.NewIngrediant & " where RecipeID=" & Me.RecipeID
    Forms!YourForm.Requery

    But again, not sure if that is what you need. Would be nice to just bind the ingrediants fields on form and just change them all on the form as needed.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Do you want to create new records in the table, or to update (change) existing records?

    If you want to add new records, then you need an Append query, not an Update.

    Can you clarify, please.

  4. #4
    Alexs66 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    2
    Click image for larger version. 

Name:	Untitled-1.jpg 
Views:	14 
Size:	87.1 KB 
ID:	25689
    Thank You for the responses. I'm wanting to update existing fields and not create new records. What i have at the moment is a query based on the current open form frm_Recipes (qry_1STCALC) which calculates the quantity by the value in the nutrient field. (nutrient field being fat. saturated fat etc) then i have a second query (qry_2NDCALC) With qry_1 being the data source. This gives me a total value for say carbohydrates in a given recipe and divides it by the amount of servings. So what i end up with is a list of values which essentially is the full nutrient value (theoretically of course) of an entire meal on a plate. This is what im trying to achieve and its these values that i wish to update to tbl_recipes into their corresponding field. When i run qry_2NDCALC i get the data Im looking for. I have tried several ways but have got no where. I can create a report and pull the data up and type it into the fields not a problem but there must be a way of automating this.

    Thanks again..

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Not sure what 2NDCALC looks like but can you maybe create a 3rd Update query based on that second query and also bring in tbl_recipe and link by RecipeID. Remember to have a good backup of the data when using Update queries.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Update/Select Query (Wont Update)
    By NickWren in forum Access
    Replies: 1
    Last Post: 03-30-2016, 10:41 AM
  2. Replies: 14
    Last Post: 08-12-2014, 06:33 AM
  3. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  4. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  5. Replies: 4
    Last Post: 11-10-2011, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums