SQL Not Updating

D

DS

This statement is not updating. All of the criteria is there, These are all
number fields.
Thanks
DS

Dim QTYSQL As String
'DoCmd.SetWarnings False
QTYSQL = "UPDATE tblCheckDetailsTMP SET tblCheckDetailsTMP.CDQuantity =
Forms!frmFXDiscountItem!TxtQTY " & _
"WHERE tblCheckDetailsTMP.CDCheckID = Forms!frmFXDiscountSelect!TxtCheckID "
& _
"AND tblCheckDetailsTMP.CDGroupID = Forms!frmFXDiscountItem!TxtGroupID " & _
"AND tblCheckDetailsTMP.CDSubGroupID =
Forms!frmFXDiscountItem!TxtSubGroupID;"
DoCmd.RunSQL (QTYSQL)
'DoCmd.SetWarnings True
 
S

Steve Sanford

Comment out the line
DoCmd.RunSQL (QTYSQL)

and add this line

Debug.Print QTYSQL

then look at the immediate window. You won't see the values form the
controls on the form because the reference to the controls are inside the
quotes. SQL doesn't know that it should use the values from the controls. For
the first field, the SQL is trying to put the text,
"Forms!frmFXDiscountItem!TxtQTY", into a numeric field. Same for the other
fields - the SQL is trying to put text onto a numeric field.

TRY this:


Dim QTYSQL As String

'DoCmd.SetWarnings False

'*** each line below should begin with QTYSQL ***
QTYSQL = "UPDATE tblCheckDetailsTMP"
QTYSQL = QTYSQL & " SET CDQuantity = " & Forms!frmFXDiscountItem!TxtQTY
QTYSQL = QTYSQL & " WHERE CDCheckID = " & Forms!frmFXDiscountSelect!TxtCheckID
QTYSQL = QTYSQL & " AND CDGroupID = " & Forms!frmFXDiscountItem!TxtGroupID
QTYSQL = QTYSQL & " AND CDSubGroupID = " &
Forms!frmFXDiscountItem!TxtSubGroupID
QTYSQL = QTYSQL & ";"


'=== for testing====
'comment out or delete after testing
Debug.Print QTYSQL
'=== for testing====

'this is faster than DoCmd.RunSQL()
CurrentDb.Execute strSQL, dbFailOnError

'DoCmd.RunSQL (QTYSQL)
'DoCmd.SetWarnings True



HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SELECT INSERT 1
Select From 1
OR or AND 2
SQL SYNTAX ERROR 8
UNION Error 9
SQL ORDER BY 1
SQL Other Database 2
SQL Not Updating 5

Top