Insert query - Type mismatch

  • Thread starter Thread starter Jarryd
  • Start date Start date
J

Jarryd

Hello,

Could someone please tell me what is wrong with my code:
----------------------------------------------------------------------------------
Private Sub btnApply_Click()
Dim Weight As Double
Dim Quantity As Long
Dim ordLink As Long
Dim qrySplit As String
Dim rstTRP As DAO.Recordset
Dim db As DAO.Database

ordLink = Form_Orders.txtOrd_Det_Lnk
Quantity = Form_Order_Details.txtQty - txtRolls
Weight = Form_Order_Details.txtWeight - txtkilos

qrySplit = "INSERT INTO Order_Details ( Orders_Link, Quantity, Weight )
VALUES (" + ordLink + ", " + Quantity + ", " + Weight + ");"

DoCmd.RunSQL ("qrySplit")

End Sub
------------------------------------------------------------------------------

I have checked the table Order_Details and the types are correct - Weight is
Double, Quanitity is Long Integer, Orders_Link is Long Integer.

TIA,

Jarryd
 
OK,

Wh do I get it now? This is excrutiating:
-----------------------------------------------------------------------
Private Sub btnApply_Click()
Dim Weight As Double
Dim Quantity As Long
Dim ordLink As Long
Dim Orig_Unique As Long
Dim Q_U As Long
Dim W_U As Double
Dim qrySplit As String
Dim qryUpd_Orig As String

ordLink = Form_Orders.txtOrd_Det_Lnk
Quantity = Form_Order_Details.txtQty - txtRolls
Weight = Form_Order_Details.txtWeight - txtkilos
Orig_Unique = Form_Order_Details.txtUnique
qrySplit = "INSERT INTO Order_Details ( Orders_Link, Quantity, Weight )
VALUES (' " & ordLink & " ', ' " & Quantity & " ', ' " & Weight & " ');"
qryUpd_Orig = "UPDATE Order_Details SET Quantity = (' " & Q_U & " '), Weight
= (' " & W_U & " ') WHERE Unique = (' " & Orig_Unique & " ');"
DoCmd.RunSQL qrySplit
DoCmd.RunSQL qryUpd_Orig

End Sub
----------------------------------------------------------------------
I have checked the types and they are correct. What am I doing wrong to get
Type Mismatch?

TIA,

Jarryd
 
Youe are putting single apostrophes around your variables. These are only for
strings. Ordlink, Quantity and Weight are Longs and Doubles so no apostrophes
required.
 
Back
Top