To few parameters. expected 2 on INSERT Query

PatrickStel

New member
Local time
Yesterday, 18:03
Joined
Dec 18, 2015
Messages
1
Hi Gents,

I've run in to a issue with VBA Query.

I'm trying to insert a query into the table with VBA but what ever I try to do it gets stuck on something.

I have this code in VBA for the inserting part.
Code:
    Dim dbs As Database

    ' Set the Current Database
    Set dbs = CurrentDb
            
    'Testing purpose
    Me.cbPenalty1 = 0
    Me.cbOwnGoal1 = 0
    ' Create a new record in the tblMatchPlayer table.
    ' Query saved the player who scored with values in a new row, linked with MatchID & PlayerID.
    MsgBox " INSERT INTO tblMatchPlayer " _
            & "(MatchID, PlayerID, SubstituteID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoal, Assist) VALUES " _
            & "(" & Me.MatchID & ", '', '', '', " & Me.cmScoreName1 & ", " & Me.tbScoreTime1 & ", '', '', '', " & Me.cbPenalty1 & ", " & Me.cbOwnGoal1 & ", " & Me.cmAssist1 & ");", vbOKOnly, "Query Show"
    dbs.Execute " INSERT INTO tblMatchPlayer " _
            & "(MatchID, PlayerID, SubstituteID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoal, Assist) VALUES " _
            & "(" & Me.MatchID & ", '', '', '', " & Me.cmScoreName1 & ", " & Me.tbScoreTime1 & ", '', '', '', " & Me.cbPenalty1 & ", " & Me.cbOwnGoal1 & ", " & Me.cmAssist1 & ");"
    
    dbs.Close
When I'm running this query and put it in a MsgBox to see the out come I'm getting this
INSERT INTO tblMatchPlayer (MatchID, PlayerID, SubstitudeID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoals, Assist) VALUES (29, '', '', '', Grozema, 34, '', '', '' 0, 0, Bruins)
So it looks okay, the empty fields are there cause I have to extends the parts writing to the table, the fields are all ready in the field.

But every time It's going through the Execute part I'm getting this error.
Run-time error '3061':
Too few parameters. Expected 2.
I've searched on the internet and found out other people were having this as well but I didn't find a solution.

Hope you guys can help me.

With kind regards,
Patrick
 
I think Grozema and Bruins should be surrounded by '', Then you also have '' 0 in one place!
So values should be: (29, '', '', '', 'Grozema', 34, '', '', '', 0, 0, 'Bruins')
 
This all comes down to syntax. You are putting '' in places that are numbers and not putting '' around text.
Text needs to be surrounded by '' and numbers can't have anything other than the number.

Your INSERT statement should look like this:
Code:
INSERT INTO tblMatchPlayer (MatchID, PlayerID, SubstitudeID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoals, Assist) VALUES (29, , , , 'Grozema', 34, , , , 0, 0, 'Bruins')
 

Users who are viewing this thread

Back
Top Bottom