Hi, I get a data type mismatch when I try to run this:
Dim db As Database
Dim rst As Recordset
Dim strItem As String
Dim strSQL As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPollyEndurance", dbOpenDynaset)
rst.MoveFirst
DoCmd.SetWarnings False
Do While Not rst.EOF
strItem = rst.Fields("Item").Value
strSQL = "INSERT INTO tblPollyResults ( [INV-BR], LikeItem, OldItem, IItemDesc,Desc1, Desc2, R2Desc1, R2Desc2, ShippedQty, IQtyUOM, ICustName, SalesAmt, FinCost, FinMargin, IPrcUOM )SELECT TOP 5 qryEnduranceMatches.IPrcUOM FROM qryEnduranceMatches WHERE (((qryEnduranceMatches.LikeItem) =" & strItem & "))ORDER BY qryEnduranceMatches.ShippedQty DESC;"
DoCmd.RunSQL strSQL
rst.MoveNext
Loop
DoCmd.SetWarnings True
End Sub
I'm trying to pass a variable in the SQL. Can I do that?
Thanks in advance for any help.
The greatest risk, is not taking one.
Dim db As Database
Dim rst As Recordset
Dim strItem As String
Dim strSQL As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPollyEndurance", dbOpenDynaset)
rst.MoveFirst
DoCmd.SetWarnings False
Do While Not rst.EOF
strItem = rst.Fields("Item").Value
strSQL = "INSERT INTO tblPollyResults ( [INV-BR], LikeItem, OldItem, IItemDesc,Desc1, Desc2, R2Desc1, R2Desc2, ShippedQty, IQtyUOM, ICustName, SalesAmt, FinCost, FinMargin, IPrcUOM )SELECT TOP 5 qryEnduranceMatches.IPrcUOM FROM qryEnduranceMatches WHERE (((qryEnduranceMatches.LikeItem) =" & strItem & "))ORDER BY qryEnduranceMatches.ShippedQty DESC;"
DoCmd.RunSQL strSQL
rst.MoveNext
Loop
DoCmd.SetWarnings True
End Sub
I'm trying to pass a variable in the SQL. Can I do that?
Thanks in advance for any help.
The greatest risk, is not taking one.