Problem with executing an SQL insert statement in access using VBA
-
27-09-2019 - |
Question
I'm trying this SQL statement but I keep getting an error
Run-time error '3061':
Too few parameters. Expected 4.
The statement I am trying to execute is:
sSQL = "INSERT INTO MasterTable (AdmissionNumber, Surname, Forename, TutorGroup) VALUES (intAdmissionNo, strSurName, strForeName, strTutorGroup)"
CurrentDb.Execute sSQL, dbFailOnError
The 4 values intAdmissionNo, strSurName, strForeName and strTutorGroup all have values and the fields all exist.
Any help is much appreciated, thanks! :)
Solution
I haven't done that from VBA, but unless I'm mistaken you're not sending in the variables as you think you are. Try this line instead of your current one:
sSQL = "INSERT INTO MasterTable (AdmissionNumber, Surname, Forename, TutorGroup) VALUES (" & intAdmissionNo & ", " & strSurName & ", " & strForeName & ", " & strTutorGroup & ")"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow