Insert into code

S

Simon

I have the below code, it does not bring up any error message but just
does not add the data to the table
Any ideas???

This is running from a subform and the OrderNumber needs to come from
the main form


Private Sub Command22_Click()
Dim cmd As ADODB.Command
Dim strSQL As String
Dim strQty As String

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


strQty = InputBox("How many to buy:", "Purchase Product")


If Len(strQty) > 0 Then
' confirm that valid number entered
If IsNumeric(strQty) Then
If IsNumeric(strQty) Then

strSQL = "INSERT INTO tblOrderProduct (ProductID,
OrderNumber, Qty) VALUES (Me.ProductID, 900, strQty)"

cmd.CommandText = strSQL



Else
MsgBox "Invalid quantity entered.", vbExclamation,
"Warning"
End If
Else
' user pressed Cancel button or entered no quantity in input
box
MsgBox "Purchase Cancelled.", vbInformation, "Purchase
Product"
cmd.Execute
End If
End If

End Sub
 
D

Douglas J. Steele

Your cmd.Execute statement would appear to be in the wrong place. I would
think it should be immediately after the line of code

cmd.CommandText = strSQL
 

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