"Argument not optional" What i need to do with this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amiraSehhuri
    New Member
    • Jan 2016
    • 4

    "Argument not optional" What i need to do with this?

    Keep getting this massage, "Compile Error: Argument Not Optional" and highlighted Me.txtSiteType
    Trying to figure up, but failed.

    Please help.

    Code:
    Private Sub cmdAdd_Click()
    'when we click on button add there are 2 option
    '1. for insert
    '2. for update
        If Me.txtSiteID.Tag & "" = "" Then
            'this is for insert new
            'Add data to table
            CurrentDb.Execute = "INSERT INTO contoh(Site ID, Site Name, Site Type) " & _
            " VALUES('" & Me.txtSiteID & "','" & Me.txtSiteName & "','" & Me.txtSiteType & "') "
            Set Data = cmdAdd_Click()
            MsgBox "Already Add"
        
        
        End If
    End Sub

    Thanks in advance,
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Try putting a space between your table name and the opening parenthesis as well as after the word VALUES.

    Comment

    • amiraSehhuri
      New Member
      • Jan 2016
      • 4

      #3
      Done, still got the same massage.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Remove the equals sign after the CurrentDb.Execu te. Also, I believe that you need square brackets around your field names because of the spaces.

        Comment

        • amiraSehhuri
          New Member
          • Jan 2016
          • 4

          #5
          OMG!, Thanks Seth Schrock. Will get nightmare because of both square bracket and "=" only.

          Comment

          • Seth Schrock
            Recognized Expert Specialist
            • Dec 2010
            • 2965

            #6
            Glad it worked. I missed it the first time as well.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32653

              #7
              Amira.

              Some tips that may prove helpful :
              1. As a general rule it is good practice to prepare your SQL in a string variable first. That way you can show the contents of the string as well as use as one of the parameters to your procedure or method. See How to Debug SQL String.
              2. Never use the result of the CurrentDb() function call directly. Always assign it once to a variable and then use the variable for all future references. CurrentDb() is a function that actually returns a different value each time it's run - even though each value represents the same database object.
              3. When referencing procedures, either subroutines or functions, it makes it easier to read your code if you use the Call syntax. EG. The syntax for Execute would be like :
                Code:
                Call dbVar.Execute(Parameter#1, Parameter#2, etc)

              Comment

              Working...