Share via

Using INSERT INTO STATEMENT ERROR

Anonymous
2016-05-24T21:26:19+00:00

I am coding in vba some access buttons, my problem is when coding the "add" button, for some reason the program doesn't accept the INSERT INTO statement and returns me the following error message : "Compile Error: Wrong number of arguments or invalid property assignment" I already checked that the number of fields declared is the same of the number of fields after the "VALUES" clause... Here is my code: 

Private Sub cmdAdd_Click()

CurrentDb.Execute "INSERT INTO tblClients(ClientId, ClientName, Gender, City, Address(Fisical), Cellphone/Telephone)" & _

" VALUES (" & Me.txtID & ",'", Me.txtName & ",'", Me.cboGender & ",'", Me.txtCity & ",'" & _

 Me.txtAddress & ",'", Me.txtCellphone & "')"

tblClients_subform.Form.Requery

End Sub

What I am doing wrong

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

13 answers

Sort by: Most helpful
  1. Anonymous
    2016-05-24T22:40:17+00:00

    gender is a combo box, it's values are "Male", "Female", ClientID it's supposed to be number (autonumber)

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2016-05-24T22:34:43+00:00

    Make sure that you spelled the field names correctly.

    Also, I assumed that ClientId and Gender are number fields, and the other four are text fields.

    If Gender is a text field, change the instruction to

        CurrentDb.Execute "INSERT INTO tblClients (ClientId, ClientName, Gender, " & _

            "City, [Address(Fisical)], [Cellphone/Telephone])" & _

            " VALUES (" & Me.txtID & ",'" & Me.txtName & "','" & Me.cboGender & _

            "','" & Me.txtCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "')"

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-05-24T22:27:54+00:00

    well, partially because now it shows me "Run-time error 3061: Too few parameters expected. expected 1"

    I am looking for the cause on the web, but thank you

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-05-24T21:56:32+00:00

    yes! it worked! Thank you sir!

    Was this answer helpful?

    0 comments No comments
  5. HansV 462.6K Reputation points
    2016-05-24T21:38:09+00:00

    Field names that contain other characters than letters, digits and underscores, must be enclosed in square brackets. Also, the single quotes and ampersands are not always used correctly.

        CurrentDb.Execute "INSERT INTO tblClients(ClientId, ClientName, Gender, " & _

            "City, [Address(Fisical)], [Cellphone/Telephone])" & _

            " VALUES (" & Me.txtID & ",'" & Me.txtName & "'," & Me.cboGender & _

            ",'" & Me.txtCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "')"

    Was this answer helpful?

    0 comments No comments