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
40 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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