Sub or Function not Defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yongo
    New Member
    • Nov 2009
    • 2

    Sub or Function not Defined

    I am getting error sub or function not defined when I am trying to save data into my database using values on controls defined in the form. The application is seeing the control name as a name of function or sub here is the code
    Code:
    If isCompanyNameExist(CompanyName) = False Then
     strSQL = "INSERT INTO Companies (CompanyID, CompanyName, PostAdr, treetAdr, AreaID, ContactID) " _
    & "Values('" & CompanyID & "','" & CompanyName & "','" _
     & PostAdr & "','" & StreetAdr & "','"  & AreaID & "','" & ContactID & "')"
        Else
          strSQL = "UPDATE  Companies " _
             & "SET CompanyID = '" & CompanyID & "',CompanyName = '" & CompanyName & "',PostAdr = '" & PostAdr & "', " _
             & "StreetAdr = '" & StreetAdr & "' ,AreaID = '" & AreaID & "',ContactID = '" & ContactID & "' " _
             & "DateModified = '" & SQLFormatDate(DateModified) & "', ModifiedBY = '" & CurrentProject.Connection.Properties("USER ID") & "' " _
             & "WHERE CompanyID = '" & CompanyID & "'"
        End If
        
        If ValueIn = False Then
          DoCmd.SetWarnings False
          DoCmd.RunSQL strSQL
          DoCmd.SetWarnings False
        End If
    Each time I try to run my code , I got the sub or function not defibed on the name of my controls in the form which are companyname, contactid, areaID etc..
    Please help
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    It is a misplaced quote or bracket.
    You need to print the query to spot the mistake as this is an SQL error.
    The VB code is little help

    Comment

    • Yongo
      New Member
      • Nov 2009
      • 2

      #3
      Thank you for your reply but I don't thing is a problem of quote or bracket. Because these variables are controls name in the form. Printing the SQL i can't since when the code enter the specific sub, it display the message highlighting my controls name. And not only in one computer but I found the same message in two differents application. Can it be, a software bug or what?

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        The values/names from your form are blank or incorrectly formatted.
        You are using them blindly to construct a query.
        I say blindly because you are not validating them in any way.
        Probably a missing quote, blank value is the problem.
        Can sometimes help to use brackets in your query where field name has a space.

        To print the query, construct it in a string, pass string to a text or message box

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Sorry to see you've been waiting some time for a further response to this question.

          Is this program written in VB6, or in Access?

          If it's in VB6, I don't think DoCmd exists, so that may be the problem. If you're in Access then DoCmd is probably Ok.

          Please tell us what is highlighted in the code when you get the
          Sub or Function not Defined error.

          Comment

          Working...