INSERT INTO

S

Simon

What could be wrong with this, its not adding the produt to the table

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) VALUES (Me.ProductID, me.ordernumber)"


cmd.CommandText = strSQL
' cmd.Execute
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"
End If
End If
 
J

John W. Vinson

What could be wrong with this, its not adding the produt to the table

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) VALUES (Me.ProductID, me.ordernumber)"


cmd.CommandText = strSQL
' cmd.Execute
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"
End If
End If

Well, the ' before cmd.Execute is making it into a comment. The query is never
being executed.
 
K

Ken Snell \(MVP\)

You need to concatenate the actual values into the SQL string:

strSQL = "INSERT INTO tblOrderProduct (ProductID, OrderNumber)
VALUES (" & Me.ProductID & ", " & me.ordernumber & ")"
 
J

Jeff Boyce

Simon

Why are you testing for strQty twice in a row, inside nested If... Then
statements?

Have you tried setting a breakpoint near the top and stepping through,
inspecting values at each step?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
A

a a r o n . k e m p f

I think that he wants the QTY inserted into the db, maybe?

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

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