A family of Microsoft relational database management systems designed for ease of use.
gender is a combo box, it's values are "Male", "Female", ClientID it's supposed to be number (autonumber)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
A family of Microsoft relational database management systems designed for ease of use.
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.
gender is a combo box, it's values are "Male", "Female", ClientID it's supposed to be number (autonumber)
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 & "')"
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
yes! it worked! Thank you sir!
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 & "')"