none
RUN-TIME ERROR 3061: Expected 1 RRS feed

  • Question

  • I am having problem with this code and I don't know where to edit from. I want to update records in the table using values in my textbox. Please help out anyone. The insert part is working very well. But the update is not. Please help me out.

    'when we click on button Add there are two options
    '1. for Insert
    '2. for Update
    If Me.MODULEID.Tag & "" = "" Then
    'this is for insert new
    'add data to table
    CurrentDb.Execute "INSERT INTO tblModules(ModuleID,CourseCode,CourseTitle,ModuleNo,StartDate,EndDate,StudyCentre,Facilitator)" & _
        "VALUES(" & Me.MODULEID & ",'" & Me.COURSECODE & "','" & Me.COURSETITLE & "','" & Me.MODULENO & "','" & Me.StartDate & "','" & _
        Me.EndDate & "','" & Me.StudyCentre & "','" & Me.Facilitator & "')"
    Else
    'otherwise (Tag of moduleID store the id of module to be modified
    CurrentDb.Execute "UPDATE tblmodules " & _
        "Set [ModuleID]=" & Me.MODULEID.Value & _
        ",CourseCode='" & Me.COURSECODE.Value & "'" & _
        ",CourseTitle='" & Me.COURSETITLE.Value & "'" & _
        ",ModuleNo='" & Me.MODULENO.Value & "'" & _
        ",StartDate='" & Me.StartDate.Value & "'" & _
        ",EndDate='" & Me.EndDate.Value & "'" & _
        ",StudyCentre='" & Me.StudyCentre.Value & "'" & _
        ",Facilicator='" & Me.Facilitator.Value & "'" & _
        "WHERE ModuleID=" & Me.MODULEID.Tag
       
    End If


    Monday, March 13, 2017 12:38 PM

All replies

  • The error indicates that there is a field name that cannot be identified. Check the column and Form names to make sure that you do not have a spelling error. Also, watch out for missing spaces:

     ",Facilicator='" & Me.Facilitator.Value & "'" & _
         " WHERE ModuleID=" & Me.MODULEID.Tag


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, March 13, 2017 12:47 PM
  • Thanks Bro. I have seen the error. But Still having some more issues in the same code.

    Another Run time Error: 3113

    ModuleID Field not updatable

    Thanks for the previous correction

    Monday, March 13, 2017 1:52 PM
  • Thanks Bro. I have seen the error. But Still having some more issues in the same code.

    Another Run time Error: 3113

    ModuleID Field not updatable

    Thanks for the previous correction


    Is ModuleID field an AutoNumber type or Primary Key? If so, you should remove it from your UPDATE SET statement.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, March 13, 2017 2:14 PM
  • 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? The Surname field datatype is short text.  Thanks in advance for the answer
    Thursday, March 23, 2017 12:27 PM
  • 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? The Surname field datatype is short text.  Thanks in advance for the answer

    Hi Ignatius,

    As Surname is of type Text, enclose it with quotes:

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

    Imb.

    Thursday, March 23, 2017 1:18 PM