Hi,
im a newbie to access and starting to use vba, to update my warehouse quantity.
i create vba code with a help of some books, well im think im doing something wrong
here is the code...
to summarize it there is a transactionline
which has transactionline id, productid(fk), TransactionTypeId(fk), Quantity, TransactionDate
ProductId has the productname and productstock. What i've done is, i create a form using the above,so if the transactiontypeId has 1(will deduct) product.stock from transanctionline.quantity, 2 will add and 3 will make stock=0
here is the code but gives me some error.
Any help will appreciate
---------------------------------------------------------
Private Sub Button_Click()
Dim mysql, mysql2, recsource, success As String
DoCmd.OpenForm "sumqtr", acViewDesign
recsource = Forms!sumqtr.RecordSource
DoCmd.Close acForm, "sumqtr", acSaveNo
Dim cnn1 As ADODB.Connection
Dim myrecordset As New ADODB.Recordset
Set cnn1 = CurrentProject.Connection
myrecordset.ActiveConnection = cnn1
mysql = "SELECT product.ProductId, Sum([TransactionLine.Quantity]) AS SumOfQuantity " & _
"FROM [ " & recsource & " ] " & _
" GROUP BY product.ProductId"
myrecordset.Open mysql
DoCmd.RunSQL mysql
If TransactionTypeId = 1 Then
mysql2 = "UPDATE Product " & _
"SET Product.apothema = SumofQuantity.transactionline - product.apothema " & _
" WHERE product.productid = transactionline!productid"
DoCmd.RunSQL mysql2
MsgBox success
myrecordset.clse
End If
End Sub
-------------------------------------------------
Any help?
Thanks