Solved Too few parameters

ClaraBarton

Registered User.
Local time
Today, 00:41
Joined
Oct 14, 2019
Messages
506
I've been over and over this:
Code:
Public Sub AddJunctionRecord(LocID As Long, ItemID As Long)
      Dim strSQl As String
10    strSQl = "INSERT INTO tblLocItem (fLocID, fItemID) " & _
                "VALUES (LocID, ItemID);"
20        CurrentDb.Execute strSQl, dbFailOnError
End Sub
Returns the error: too few parameters; expected 2
On break LocID returns the value of 4 and ItemID returns the value of 376.
The junction table only has 2 fields besides the autonumber.
What is it talking about?
 
Even if they're actual field names and not variables? The Insert statement isn't that way. Is it right?
 
Wait... Now it says too few parameters; expected 4. Is it playing with me?
Code:
Public Sub AddJunctionRecord(LocID As Long, ItemID As Long)
      Dim strSQl As String
10    strSQl = "INSERT INTO tblLocItem (fLocID, fItemID) " & _
                "VALUES (“ & LocID & “,” & ItemID & “);"
20        CurrentDb.Execute strSQl, dbFailOnError
End Sub
 
My guess is you copied from a word processor because you have Smart Quotes arround LocID and ItemID not straight quotations. Need to get rid of Smart Quotes.
 
ahh... if anyone cares, here's what works:
Code:
Public Sub AddJunctionRecord(LocID As Long, ItemID As Long)
      Dim strSQl As String
10    strSQl = "INSERT INTO tblLocItem (fLocID, fItemID) " & _
                "VALUES(" & LocID & ", " & ItemID & ");"
20        CurrentDb.Execute strSQl, dbFailOnError
End Sub
 
Last edited:
 
Even if they're actual field names and not variables? The Insert statement isn't that way. Is it right?
always helps if you debug.print your sqlstr before executing it. If still not obvious what the problem is, copy the string from the immediate window and paste to a new query and try to execute it from there
 

Users who are viewing this thread

Back
Top Bottom