I have a SQL string in a set of code in VBA for Access. The code is:
Private Sub Command40_Click()
Dim strSQL As String
Dim db As DAO.Database
strSQL = "Delete * From TEMP_AssignSequence"
Set db = CurrentDb()
db.Execute strSQL
Call ResetSeed("TEMP_AssignSequence")
strSQL = "PARAMETERS [Forms]![JobQuote]![JobID] Short;"
strSQL = "INSERT INTO TEMP_AssignSequence ( CaptionText )"
strSQL = strSQL & " SELECT tblContractors.Contractor"
strSQL = strSQL & " FROM tblContractors INNER JOIN tblContractorJob ON tblContractors.ContractorID = tblContractorJob.ContractorID"
strSQL = strSQL & " WHERE (((tblContractorJob.JobID)=[Forms]![JobQuote]![JobID]))"
strSQL = strSQL & " GROUP BY tblContractors.Contractor"
strSQL = strSQL & " Order By tblContractors.Contractor;"
db.Execute strSQL
End Sub
When I build the query in the design window, it outputs the same exact string. However, when I try to run this code, I get the error 3061: Too few parameters. Expected 1
I am a little confused since this runs perfectly when in a query, but wont run via VBA as a string. I assume I am handling my WHERE incorrectly as far as VBA is concerned?