Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
54 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

856 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