SQL Query Error

I have created an inventory program but have run into some troubles when updating the database. The user pulls data from one msflexgrid (parent category), and the inventory items with the same description are displayed on a second msflexgrid (child). When the user clicks on the second msflexgrid, the data is dropped into text boxes for edititing. However, when the user presses the "update" command button I keep getting an SQL Query error. Could someone please look at my code and show me what I have done wrong.. thanks in advance!

Case "UPDATE"
   
        If IsValidData = True Then
       
        Select Case strCategory
       
            Case "MOTHERBOARD"
                         
               strMySQL = "UPDATE tblDataChild.* SET " & " tblDataChild.[ItemDescription]='" & Trim(Me.txtItemDescription.Text) & "'" & " tblDataChild.[ItemMOBOID]='" & Trim(Me.txtMoboID.Text) & "'" & " tblDataChild.[ItemLocation]='" & Trim(Me.txtLocation.Text) & "'" & " tblDataChild.[ItemOwner]= '" & Trim(Me.dcbOwner.Text) & "'" & " tblDataChild.[ItemStatus]='" & Trim(Me.dcbStatus.Text) & "'" & " tblDataChild.[ItemRemovedDate]='" & Trim(Me.txtItemRemovedDate.Text) & "'" & " WHERE tblDataChild.[ID]='" & Trim(Me.txtID.Text) & "'"""
                                           
                Set UpdateDB = New ADODB.Connection
                UpdateDB.ConnectionString = dbConString
                UpdateDB.mode = adModeReadWrite
                UpdateDB.Open
                UpdateDB.Execute strMySQL, adExecuteNoRecords
                UpdateDB.Close
                 
                SSTab1.Tab = 1
                Me.txtMoboID.Locked = False
                Me.txtMoboID.Enabled = True
                Me.lblMoboID.Enabled = True
           
                With MSFlexGrid2
                For i = 0 To .Rows - 1
                    For j = 0 To .Cols - 1
                        .Row = i
                        .Col = j
                        If .Text = "" Then
                            .Text = "  " & i & " " & j
                            .Text = "  "
                        End If
                    Next j
                Next i
                   
            End With
           
            mode = adModeReadWrite
            loc = adUseClient
           
            ConnectToDB mode, loc, dbConString
       
            Set rs = New ADODB.Recordset
           
            rs.Open "SELECT * FROM tblDataChild", DbCon, adOpenForwardOnly, adLockOptimistic
            mystring = "|MOBO ID|INVENTORY ITEM|STORAGE LOCATION|OWNER|STATUS|"
            MSFlexGrid2.FormatString = mystring
            MSFlexGrid2.ColWidth(0) = 0
            MSFlexGrid2.ColWidth(1) = 775
            MSFlexGrid2.ColWidth(2) = 2700
            MSFlexGrid2.ColWidth(3) = 1700
            MSFlexGrid2.ColWidth(4) = 700
            MSFlexGrid2.ColWidth(5) = 2200
            MSFlexGrid2.ColWidth(6) = 0
            MSFlexGrid2.ColWidth(7) = 0
            MSFlexGrid2.Rows = 1
           
            If rs.RecordCount > 0 Then
                rs.MoveFirst
                           
                If Not rs.EOF Then
                    x = 0
                    Do While Not rs.EOF
                        MSFlexGrid2.Rows = MSFlexGrid2.Rows + 1
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 0) = rs.Fields("ID")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 1) = rs.Fields("ItemMOBOID")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 2) = rs.Fields("ItemDescription")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 3) = rs.Fields("ItemLocation")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 4) = rs.Fields("ItemOwner")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 5) = rs.Fields("ItemStatus")
                        MSFlexGrid2.TextMatrix(MSFlexGrid2.Rows - 1, 6) = rs.Fields("ItemRemovedDate")
                        x = x + 1
                        rs.MoveNext
                        Loop
                End If
                Me.lblQTY.Caption = x
            End If
            CloseConnection
           
            Me.txtItemDescription.Text = ""
            Me.txtLocation.Text = ""
            Me.dcbStatus.Text = ""
            Me.dcbStatus.Enabled = True
            Me.dcbOwner.Text = ""
            Me.txtMoboID.Text = ""
            cmdSaveNew.Caption = "SAVE"
YeavisAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
peh803Connect With a Mentor Commented:
Try it like this:

strMySQL = "UPDATE tblDataChild SET ItemDescription='" & Trim(Me.txtItemDescription.Text) & "', ItemMOBOID='" & Trim(Me.txtMoboID.Text) & "', ItemLocation='" & Trim(Me.txtLocation.Text) & "', ItemOwner= '" & Trim(Me.dcbOwner.Text) & "', ItemStatus='" & Trim(Me.dcbStatus.Text) & "', ItemRemovedDate='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE ID='" & Trim(Me.txtID.Text) & "'"
0
 
peh803Commented:
What error are you getting?  Can you provide some more specific information on this?

Offhand, the composition of your update statement appears questionable...

Try changing it to this:
strMySQL = "UPDATE tblDataChild SET " & tblDataChild.[ItemDescription] & "='" & Trim(Me.txtItemDescription.Text) & "', " & tblDataChild.[ItemMOBOID] & "='" & Trim(Me.txtMoboID.Text) & "', " & tblDataChild.[ItemLocation] & "='" & Trim(Me.txtLocation.Text) & "', " & tblDataChild.[ItemOwner]= '" & Trim(Me.dcbOwner.Text) & "', " & tblDataChild.[ItemStatus] & "='" & Trim(Me.dcbStatus.Text) & "', " & tblDataChild.[ItemRemovedDate]='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE tblDataChild.[ID]='" & Trim(Me.txtID.Text) & "'"

Hope this helps,
peh803
0
 
YeavisAuthor Commented:
The message I am getting is: SYNTAX ERROR IN QUERY. INCOMPLETE QUERY CLAUSE.

I will try your code and see if it helps..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
peh803Commented:
Sounds good ... If I understand correctly how you're trying to piece together your update statement, my suggestions should help.

Thanks,
peh803
0
 
YeavisAuthor Commented:
The code above errored out stating invalid use of brackets.

All I want is a query that will update the following fields, bracket is not required and it's only in there because I was trying to get it to work and thought I would give it a shot. Here are the fields I need updated:

tblDataChild:
ID (index - no updating, obviously)
ItemMoboID (Need a query with this included, and one with out. Depends on the type of inventory being input..)
ItemDescription
ItemLocation
ItemOwner
ItemStatus
ItemRemovedDate (this is option, can be left blank. How could I replace NULL values here??)

Thanks..
0
 
YeavisAuthor Commented:
Now I'm getting a "DATA TYPE MISMATCH IN QUERY EXPRESSION" message... any idea's??
0
 
peh803Commented:
yes, the data type mismatch indicates that you're trying to insert a string into a non-character type field.  What are the database data types for the fields you're updating?

peh803
0
 
YeavisAuthor Commented:
They are all text..  I don't modify the ID, and that is a long integer (autoincrement).
0
 
YeavisAuthor Commented:
Is there anyone else that can help me out here?? I need to get this project completed by tomorrow and I can't resolve this issue!!
0
 
viola123Commented:
hehe... try this:

strMySQL = "UPDATE tblDataChild SET ItemDescription=" + Trim(Me.txtItemDescription.Text) +" ItemMOBOID=" + Trim(Me.txtMoboID.Text)+" ItemLocation=" + Trim(Me.txtLocation.Text)+" ItemOwner="+Trim(Me.dcbOwner.Text) +" ItemStatus="+Trim(Me.dcbStatus.Text) +" ItemRemovedDate]="+Trim(Me.txtItemRemovedDate.Text)+" WHERE ID=" +Trim(Me.txtID.Text)


cheers
viola
0
 
viola123Commented:
one suggestion:

i suggesting check the value of strMySQL using debugger. if there is anyting wrong, i am sure you can find something abnormal in that query string variable.


cheers
viola
0
 
YeavisAuthor Commented:
I am getting a missing operator error now..  I will try to use the debugger and see if I get anything.
0
 
YeavisAuthor Commented:
Would you recommend create string variables in place of using Trim(me.txtLocation.text)?
0
 
YeavisAuthor Commented:
No matter what I do I keep getting DATA TYPE MISMATCH errors. The first field in my database is ID and it is not updateable, but when change the syntax of strMySQL to strMySQL = "UPDATE tblDataChild SET ID = '" & trim(me.txtID.text) & "'" & " WHERE ID='" & trim(me.txtID.text) & "'"   it tells me that the field ID is not updateable. This is the only time I get anything besides a DATA TYPE MISMATCH error...
0
 
Helena Markováprogrammer-analystCommented:
If the column ID in a table is not updateable then why are you trying to update it ?
0
 
peh803Commented:
Is this still a problem for you?

peh803
0
 
huyntminhCommented:
Why don't you post here your table create script. It will be easier to firgure out your bugs with the exact table structure.
0
 
huyntminhCommented:
Try this instead :

strMySQL = "UPDATE tblDataChild SET ItemDescription='" & Trim(Me.txtItemDescription.Text) & "', ItemMOBOID='" & Trim(Me.txtMoboID.Text) & "', ItemLocation='" & Trim(Me.txtLocation.Text) & "', ItemOwner= '" & Trim(Me.dcbOwner.Text) & "', ItemStatus='" & Trim(Me.dcbStatus.Text) & "', ItemRemovedDate='" & Trim(Me.txtItemRemovedDate.Text) & "'  WHERE ID=" & Trim(Me.txtID.Text)
0
 
peh803Commented:
@Yeavis:

This question hasn't been touched in quite some time....

Please update us on the status.  If you still need help, let us know.  Otherwise, please award points according to whoever you think deserves them, and close the question.

Thanks for your help!
peh803
0
All Courses

From novice to tech pro — start learning today.