Solved

MS Access Update Query How to Update All The Records On A Continuous Form Not Just The One I'm On

Posted on 2016-11-06
3
24 Views
Last Modified: 2016-11-06
I have a form that I am wanting to be able to update ALL the records on the form not just the one I am on.
How can I do this?

Thanks!

ProductID Combo Box 1:
SELECT Products.ProductID, [Skus].[Sku] & "" & [Conditions].[CondCode] AS [Product SKU]
FROM SKUs INNER JOIN (Conditions INNER JOIN Products ON Conditions.ConditionID = Products.ConditionID) ON SKUs.SkuID = Products.SkuID;

Open in new window



ProdLocLocID ComboBox 2:
SELECT ProdLocations.ProdLocID, ProdLocations.ProductID, Locations.LocNm
FROM Locations INNER JOIN ProdLocations ON Locations.LocID = ProdLocations.LocID
WHERE (((ProdLocations.ProductID)=[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![ProductID]));

Open in new window



Update Query Deduct Values From table ProdLocations
Where ProdLocLocID = [ProdLocations].[LocID]:
UPDATE (Products INNER JOIN ProdMovements ON Products.ProductID = ProdMovements.ProductID) 
INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID SET ProdLocations.QtyLoc = [qtyloc]-[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![QtyMove]
WHERE (((ProdMovements.ProdLocLocID)=[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![ProdLocLocID]) AND ((ProdLocations.ProdLocID)=[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![ProdLocLocID]));

Open in new window

0
Comment
Question by:Dustin Stanley
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41876395
Forget queries and loop once through the RecordsetClone of the form and, for each record, perform the update - like you have been shown before.

Much easier, faster, and cleaner.

/gustav
0
 

Author Comment

by:Dustin Stanley
ID: 41876411
Thank you Gustav. I just logged back in to erase this question. I did like you showed me before.

Private Sub Command34_Click()

If Not (Recordset.EOF And Recordset.BOF) Then
    Recordset.MoveFirst 'Good habit
    Do Until Recordset.EOF = True

        'DoCmd.SetWarnings False
DoCmd.OpenQuery "qryStockTransferDeductFrom"
DoCmd.OpenQuery "qryStockTransferAddTo"
'DoCmd.SetWarnings True


        'Move to the next record. Don't ever forget to do this.
        Recordset.MoveNext
        
    Loop
Else
    MsgBox "There are no records in the recordset."
End If

MsgBox "Finished looping through records."

'Recordset.Close 'Close the recordset

End Sub

Open in new window


The only issue though I have now is my Addidtion "qryStockTransferAddTo". If I have two rows with the same [LocID] it will multiply the update by however many rows there are. Say I put qtymove 5 and have 3 rows with [LocID] 10 then it makes them all 15.

UPDATE Products INNER JOIN ((Locations INNER JOIN ProdLocations ON Locations.LocID = ProdLocations.LocID) INNER JOIN ProdMovements ON Locations.LocID = ProdMovements.LocID) ON (Products.ProductID = ProdLocations.ProductID) AND (Products.ProductID = ProdMovements.ProductID) SET ProdLocations.QtyLoc = [qtyloc]+[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![QtyMove]
WHERE (((ProdMovements.LocID)=[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![LocID]) AND ((Locations.LocID)=[Forms]![frmStillBinded]![frmStockTransferbinded].[Form]![LocID]));

Open in new window

0
 

Author Closing Comment

by:Dustin Stanley
ID: 41876472
Thanks!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now