locked
Run-time error '3061': Too few parameters. Expected 1. RRS feed

  • Question

  • Hello! I need some professional advice on my codes. I can't see where the problem is here

      
     CurrentDb.Execute "DELETE FROM Subject " & _
     " WHERE SubjCode=" & Me.frmSubjSub.Form.Recordset.Fields("SubjCode")
    It says it has too few parameters, expected 1. where "Subject" is a Table and "SubjCode" is a field name.


    Sunday, October 25, 2015 4:12 PM

All replies

  • Hi. Just a guess but try doing it this way instead:

    CurrentDb.Execute "DELETE FROM Subject WHERE SubjCode='" & Me.frmSubjSub.Form!SubjCode & "'", dbFailOnError

    That assumes SubjCode is a Text field. If it's numeric, just take out the single quotes I added. Hope that helps...

    Sunday, October 25, 2015 4:19 PM
  • Thanks for the answer DB guy but the code also gets an error. Compile error: Method or data member not found. 

    Private Sub cmdDelete_Click() If Not (Me.frmDeptSub.Form.Recordset.EOF And Me.frmDeptSub.Form.Recordset.BOF) Then If MsgBox("Are you sure you want to Delete?", vbYesNo) = vbYes Then CurrentDb.Execute "DELETE FROM Subject WHERE SubjCode='" & Me.frmSubjSub.Form!SubjCode & "'", dbFailOnError frmDeptSub.Form.Requery End If End If End Sub

    This is it's whole button code. i'm not sure if this helps


    Sunday, October 25, 2015 5:32 PM
  • Hi. So, are you trying to run this code on a main form and want to use a value from the subform as a criteria? That's what it looks like from here - just need to confirm it. If so, please double-check the name of the subform control as it may not be the same as the name of the form itself.
    Sunday, October 25, 2015 5:56 PM
  • Why are you referencing a member of the form's Recordset's Fields collection rather than referencing the column directly with:

        Me.frmSubjSub.Form.SubjCode

    Also note that frmSubjSub should be the name of the subform control in the parent form's Controls collection, which, as Db Guy pointed out, might not necessarily be the same as the source form object.

    Ken Sheridan, Stafford, England

    Sunday, October 25, 2015 6:38 PM
  • Yes. The form looks like this:

    Monday, October 26, 2015 12:59 PM
  • Wrong upload. This is the form.

    Monday, October 26, 2015 1:03 PM
  • That doesn't tell us a lot, I'm afraid.  What is the name of the subform control, i.e. the control in the parent form's Controls collection which houses the subform?  From your earlier post we can probably assume the name of its source form object is frmSubjSub, but we don't know if this is also the name of the subform control or not.  It is the latter via which a subform is referenced, not the name of the source form object.

    However, I'm puzzled as to why both the parent form and the subform appear to have SubjCode  controls, and the former is Null, but the latter has distinct values in the subform.  Looking at your form one would expect the former to be referenced as the subform's LinkMasterFields property and the latter to consequently show the same value in each row of the subform.  That is apparently not the case.  Can you explain in detail how the parent form and subform relate to each other, and on what basis the DELETE operation is intended to operate.  If you are attempting to delete one or more rows with the SubjCode value entered in the parent form's control, then you do not need to reference the subform at all, other than requerying it after the DELETE operation has been executed, in order to reload the subform's recordset so that the deleted row or rows no longer appear in the subform.

    Ken Sheridan, Stafford, England

    Monday, October 26, 2015 5:26 PM
  • Each form has the same name of the table which the data is input. The subform in the form is only to display what's inside the table. As you can see, the subform's name is under each table on the left part. The delete button is only to delete a record or a row in the subform and the parent table.
    Thursday, October 29, 2015 1:21 PM
  • It's the name of the subform *control* in the parent form's Controls collection which is relevant, not the name of the form object.  The two can be the same, though this is not advisable as it allows ambiguity in terms of what is being referenced.

    Ken Sheridan, Stafford, England

    Thursday, October 29, 2015 1:39 PM
  • Hello! I need some professional advice on my codes. I can't see where the problem is here

      
     CurrentDb.Execute "DELETE FROM Subject " & _
     " WHERE SubjCode=" & Me.frmSubjSub.Form.Recordset.Fields("SubjCode")
    It says it has too few parameters, expected 1. where "Subject" is a Table and "SubjCode" is a field name.


    Hi k0m4m3,

    To make a trouble shooting, I suggest you print result of the code below to check which command currentDb execute, check whether the value is right for Me.frmSubjSub.Form.Recordset.Fields("SubjCode"), and then paste the delete command in a query design to check whether you would get same error.

    Debug.Print "DELETE FROM Subject " & _
     " WHERE SubjCode=" & Me.frmSubjSub.Form.Recordset.Fields("SubjCode")

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 30, 2015 3:20 AM
  • Hi k0m4m3,

    Have your issue been resolved? If you have, it would be appreciated if you could share us your solution. If not, please feel free to let us know your current situation.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, November 2, 2015 6:52 AM