Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2005, 08:26 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Crisan,

Here you go!

Step 1:

Create a query called qryDeleteOrderPlace with this sql:

DELETE OrderPlace.*
FROM OrderPlace;

Step 2:

Create a query called qryOrderPlace with this sql:

SELECT Products.PID, Products.NeededQty, SupplierStocks.StockA, SupplierStocks.StockB, SupplierStocks.StockC, SupplierStocks.StockD, SupplierStocks.StockE
FROM Products INNER JOIN SupplierStocks ON Products.PID = SupplierStocks.PID;

Step 3:
Create a button on your form and put this in the on click event:

   DoCmd.SetWarnings False
   DoCmd.OpenQuery "qryDeleteOrderPlace" ' This Deletes All records in the OrderPlace Table
   Dim db As Database
   Dim rs, rsOrderPlace As Recordset
   Set db = CurrentDb
   Set rs = db.OpenRecordset("qryOrderPlace")
   Set rsOrderPlace = db.OpenRecordset("OrderPlace")
   With rs
      If Not (.EOF And .BOF) Then
         .MoveFirst
         Do While Not .EOF
               myNeededQty = !NeededQty
               myPId = !PID
               myOrderA = 0
               myorderB = 0
               myorderC = 0
               myorderD = 0
               myorderE = 0
               If !StockA >= myNeededQty Then
                  myOrderA = myNeededQty
                  myNeededQty = 0
               Else
                  myOrderA = !StockA
                  myNeededQty = myNeededQty - myOrderA
               End If
               If !StockB >= myNeededQty Then
                  myorderB = myNeededQty
                  myNeededQty = 0
               Else
                  myorderB = !StockB
                  myNeededQty = myNeededQty - myorderB
               End If
               If !StockC >= myNeededQty Then
                  myorderC = myNeededQty
                  myNeededQty = 0
               Else
                  myorderC = !StockC
                  myNeededQty = myNeededQty - myorderC
               End If
               If !StockD >= myNeededQty Then
                  myorderD = myNeededQty
                  myNeededQty = 0
               Else
                  myorderD = !StockD
                  myNeededQty = myNeededQty - myorderD
               End If
               If !StockE >= myNeededQty Then
                  myorderE = myNeededQty
                  myNeededQty = 0
               Else
                  myorderE = !StockE
                  myNeededQty = myNeededQty - myorderE
               End If
               With rsOrderPlace
                      .AddNew
                      !PID = myPId
                      !OrderA = myOrderA
                      !OrderB = myorderB
                      !OrderC = myorderC
                      !OrderD = myorderD
                      !OrderE = myorderE
                      .Update
               End With

        .MoveNext
        Loop
      End If
   End With
   Set db = Nothing
   Set rs = Nothing
   Set rsOrderPlace = Nothing
   DoCmd.SetWarnings True

That's it.

Please let me know if it works for you.

Kevin


dartcoach
 
Old September 10th, 2005, 09:59 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kevin, it works perfect! Thanks a lot!

 
Old September 10th, 2005, 10:04 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Crisan,

You're more than welcome, glad I could help. By the way, who is going to have access to the form that runs this? Because it doesn't affect any tables, it can be run anytime someone clicks on the button. You might want to think about protecting the button.

Kevin

dartcoach





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting certificate off smart card kuznickic C# 2005 1 June 16th, 2006 11:24 AM
dynamic smart tag Medes VS.NET 2002/2003 0 April 13th, 2006 12:59 PM
Smart navigation Baby_programmer ASP.NET 1.0 and 1.1 Basics 2 August 31st, 2004 06:28 AM
smart device extensions aadz5 C# 0 January 7th, 2004 05:16 PM
Smart Error Traping Ned Pro VB 6 4 September 11th, 2003 05:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.