2

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! :)

2
  • Where have you provided the actual values that you want to insert??? Commented Nov 22, 2010 at 13:10
  • They're previously declared, they show up in the watch window as well. (but admission no will be a number that changes, the forname/surname are forname/surname and tutorgroup changes also). One example might be: ...VALUES (5040, Smith, John, 10R) Commented Nov 22, 2010 at 13:19

1 Answer 1

4

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 & ")"
Sign up to request clarification or add additional context in comments.

4 Comments

Ahh thanks, but that now gives me a run time error 3075. Syntax Error (missing operator) in query expression '10R'. (10R is what TutorGroup has evaluated it)
tutorgroup is alphabetic, not numeric, add quotes ", '" & strTutorGroup & "')"
Ahh, thanks :) I put quotes around all the strings and it worked. Although now I seem to get an error every time someone's name has an apostrophe in it. Any ideas how to get round this without removing the apostrophes?
@Tim: Replace any instance of an apostrophe with two apostrophe's. Something like this Surname = Replace(Surname, "'", "''") I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.