VBA

N

NigelW_SWUK

I wish to update the units in stock when orders are added. Ken kindly gave
me the following script but I get the error Variable to be declared before
use. He said that I had to ...First make sure that you have a reference to
the Microsoft ActiveX Data
Objects Library (Tools | Refrences on the VBA menu bar).
This I don't understand - will this cause my run error?

Put the following code in the order details subform's AfterInsert event
procedure

Dim cmd As ADODB.Command
Dim strSQL As String

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

strSQL = "UPDATE Products " & _
"SET UnitsInStock = UnitsInStock - " & _
Me.Quantity & " WHERE ProductID = " & _
Me.ProductID

cmd.CommandText = strSQL
cmd.Execute
 
M

Maurice

Yes it does. Ken describes in this line how to do this:
[Tools | Refrences on the VBA menu bar]

So go to the VBEditor and look in the menubar for the word "Tools". Check
the checkbox which Ken describes and recompile.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top