INSERT INTO STATEMENT ERROR

Ukaoha Eze
Ukaoha Eze used Ask the Experts™
on
Currentdb.Execute "INSERT INTO tblRegister(Surname,FirstName,MiddleName,Email)" & _
    " VALUES(" & Me.txtSurname & ",'" & Me.txtFName & "','" & Me.txtMName & "','" & Me.txtEmail & "')"

The code above gives me run time error 3061: Too Few parameter: expected 1

Also, I discovered that when I typed (1) the figure (1) into the surname textbox on my form. It inserts into the table tblRegister without the error. How can I make it insert name (letter) into the surname and not a number? Thanks in advance for the answer
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer
Commented:
Try this
Currentdb.Execute "INSERT INTO tblRegister(Surname,FirstName,MiddleName,Email)" & _
    " VALUES('"  & Me.txtSurname & "','" & Me.txtFName & "','" & Me.txtMName & "','" & Me.txtEmail & "')"

Open in new window

Software Team Lead
Commented:
you should do this in case the user is entering single quote ' in to the text fields for better error handling.

Currentdb.Execute "INSERT INTO tblRegister(Surname,FirstName,MiddleName,Email)" & _
    " VALUES('" & replace(Me.txtSurname,"'","''") & "','" & replace(Me.txtFName,"'","''") & "','" & replace(Me.txtMName,"'","''") & "','" & replace(Me.txtEmail,"'","''") & "')"

Open in new window

Author

Commented:
Thanks so much. It all worked very well. Actually.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Ryan ChongSoftware Team Lead

Commented:
which comment(s) works for you? you may proceed to close this question.
Ryan ChongSoftware Team Lead

Commented:
please comment before we close this question.
Ryan ChongSoftware Team Lead

Commented:
suggested solutions resolved the issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial