Sample VBA code to update Multiple tables/Querries from (1 Viewer)

Moore71

DEVELOPER
Local time
Today, 00:53
Joined
Jul 14, 2012
Messages
158
Hi all,
can someone here give me sample VBA code to UPDATE Multiple tables/Querries at the same time from one FORM?
I have the following code which I don't know the reason why it is not working after series of trials:


Private Sub cmdSales_Click()
On Error Resume Next
Dim SQL As String
Dim SQL2 As String


SQL = "UPDATE tblOutbound INNER JOIN tblItem ON tblOutbound.ItemID = tblItem.ItemID SET tblItem.QtyAvail = [tblItem].[QtyAvail]-[tblOutbound].[QtyOut], tblItem.UnitSale = [tblOutbound].[ExtendedPrice] WHERE (((tblOutbound.InvoiceNo)=[forms]![frmPoS]![InvoiceNo]));"
SQL2 = "UPDATE tblClient INNER JOIN tblOutbound ON tblClient.ClientID = tblOutbound.ClientID SET tblClient.ClientAcc = [tblClient].[ClientAcc]+[tblOutbound].[AmountRecorded] WHERE (((tblOutbound.InvoiceNo)=[forms]![frmPoS]![OutboundInv]));"
'SQL = "UPDATE SalesQRY SET ClientAcc = ClientAcc + AmountRecorded, QtyAvail = QtyAvail - QtyOut WHERE InvoiceNo = forms!frmPoS!OutboundInv;"
'CurrentDb.Execute "UPDATE SalesQRY SET UnitSale = ExtendedPrice, QtyAvail = QtyAvail - QtyOut WHERE InvoiceNo = forms!frmPoS!OutboundInv;"

DoCmd.SetWarnings False

DoCmd.RefreshRecord

DoCmd.RunSQL SQL

DoCmd.RunSQL SQL2

DoCmd.SetWarnings True

Me.cmdSales.Enabled = False
Me.cmdDelete.Enabled = False
Me.cmdPrint.Enabled = True
Me.cboClient.Enabled = False

DoCmd.OpenForm "frmCustomerPay2", acNormal, , , acFormEdit, acDialog

End Sub
-------------------------------------------------------------------------------------------------
Thanks in advance
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:53
Joined
Aug 30, 2003
Messages
36,125
You haven't said why/how it's not working, so hard to debug. Perhaps the greater issue is why you're doing it. Most of us would not try to keep track of quantity on hand, total amount sold, etc. You calculate that type of thing as needed. There's a discussion of why here:

http://allenbrowne.com/AppInventory.html
 

JHB

Have been here a while
Local time
Today, 01:53
Joined
Jun 17, 2012
Messages
7,732
Comment out the "On Error Resume Next" and "DoCmd.SetWarnings False" then run the code.
If you get any error, write in which code line + error number and description.
 

Users who are viewing this thread

Top Bottom