Im having trouble with this one segment of my code where Im just trying to insert 4 values into their respective 4 fields in a table called SumTable. I looked up several solutions and looks like nothing is wrong. I used Debug.Print and it shows the exact line I want to be executed.
("INSERT INTO SumTable VALUES (Bailey,Jessica,4,2);")
It shouldnt be complicated, I dont understand what it wants from me.
Any help would be appreciated, thanks!
`
Dim data As DAO.Database
Set data = CurrentDb
DoCmd.OpenTable "SumTable", acViewNormal, acAdd
Str_Sql = "INSERT INTO SumTable VALUES (" & strlast & "," & first & "," & count & "," & countfin & ");"
Debug.Print Str_Sql
data.Execute Str_Sql
DoCmd.Close acTable, "SumTable", acSaveYes`
CodePudding user response:
As the first two variables are strings, you will need to wrap them in single quotes. Something like:
Str_Sql = "INSERT INTO SumTable VALUES ('" & strlast & "','" & first & "'," & count & "," & countfin & ");"
I would also suggest renaming count
as it is a reserved word in Access - List of Reserved Words in Access. This will stop other problems in future.