Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variable into SQL?

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
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.
 
oh, they both are string fields

The greatest risk, is not taking one.
 
Try enclosing the variable in single quotes.

"Teamwork means never having to take all the blame yourself."
 
But of course, thank you very much Genomon!

The greatest risk, is not taking one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top