Run-time error message: Too Few Parameters

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have the following code to delete data on a table using a form, but I am getting a Run-time error '3061': Too few parameters. Expected 1.

I am using this code in another form/table in my database and it works perfectly, but for some reason it is not working for the form/table I want to use now. What am I missing?

Code:
Private Sub DeleteUser_Click()
    If MsgBox("Are you sure you want to delete?", vbYesNo) = vbYes Then
        CurrentDb.Execute "DELETE FROM Employees" & _
               " WHERE UserName =" & Me.UserName
    End If


Thank you,
Miriam
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Be sure the field also has a textbox/control called [UserName]. Otherwise, Me.UserName field will be unknown to Access:
Code:
CurrentDb.Execute "DELETE FROM Employees" & _
               " WHERE UserName =" & Me.UserName

For what it's worth, if username is text I would also expect that the username parameter be in single or double quotes (single quotes are easier to use inside an already double-quoted expression).
Code:
CurrentDb.Execute "DELETE FROM Employees" & _
               " WHERE UserName = [COLOR="#FF0000"][B]'[/B][/COLOR]" & Me.UserName & "[B][COLOR="#FF0000"]'[/COLOR][/B]"

Clearly, the table itself you are using must also have that field named "UserName" as well.
 
Upvote 0
Hello,

The code worked perfectly.

Thank you,
Miriam
 
Upvote 0

Forum statistics

Threads
1,221,819
Messages
6,162,155
Members
451,749
Latest member
zack_ken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top