What's Wrong with this Code?

Posted on 2009-12-19
Last Modified: 2012-05-08

In the attached code, I'm passing in a form object and then building a SQL string based on controls on that form.  The line with "VALUES" in it tells me that the object "won't support this property or method".  What am I missing?
Public Function nInsertTaskFromForm(taskForm As Form)



    If taskForm.Name <> "frmTask" Then

        nInsertTaskFromForm = -1

        Exit Function

    End If


        ' insert record into TASKS table

    sSQL = "INSERT INTO Tasks "

    sSQL = sSQL + "(taskForm.Tasks_Description"

    sSQL = sSQL & ",taskForm.Tasks_Short_Desc"

    sSQL = sSQL & ",taskForm.Tasks_Start_Date"

    sSQL = sSQL & ",taskForm.Status) "

    sSQL = sSQL & "VALUES('" & taskForm.txtTaskDesc.Text & "'"

    sSQL = sSQL & ",'" & taskForm.txtTaskShortDesc.Text & "'"

    sSQL = sSQL & ",#" & taskForm.txtStartDate & "#"

    sSQL = sSQL & "," & CStr(geWorkStatus.Due) & ")"

    gdbKnowledgeTracker.Execute sSQL


    nNewTaskID = nGetMaxRecordIDFromTable(gdbKnowledgeTracker, "Tasks", "Task_ID")


End Function

Open in new window

Question by:NigelRocks
    LVL 3

    Accepted Solution

    The Line should read:-

    SQL = sSQL & "VALUES('" & taskForm.controls("txtTaskDesc").Text & "'"

    LVL 16

    Assisted Solution

    Check for empty variables when building the SQL string.
    You can replace empty ones with NULL (if allowed in table) or replace with a default value.
    LVL 69

    Assisted Solution

    by:Éric Moreau
    Your taskForm parameter is declared as a generic Form which does not contain any controls. Declare it as a real form.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now