PDA

View Full Version : sql update query code removing records maybe?



OTWarrior
07-17-2008, 01:59 AM
This code is part of a much larger proceedure, but the problem I am having is very occasionally, the current record from the table (referred to in the code below) is deleted. The rest of the code in this proceedure is very much of a read only nature (just reading values), and this section is the only part that can amend a record.

I am just wondering if there is a problem with an update query, can it delete a record? i wouldn't have thought it coudl do it, but I can't figure out why this is happening.

Thanks in advance for any help

sql = "UPDATE tbl_DOM_Bookings SET tbl_Bookings.EmailSent = True WHERE _
(((tbl_Bookings.anBookingID)=" & nBookingNumber & "));"
DoCmd.RunSQL (sql)

CreganTur
07-17-2008, 05:31 AM
An Update Query should never delete records... the closest thing you could do is update the value to empty string.

How do you know that the records are being deleted? Are they no longer in a table, or are they no longer showing on a Form? Could there be a filter that is just keeping them from being seen after they are updated (for instance, are you filtering for tbl_Bookings.EmailSent = True?).

Also, when I put your SQL code into a module it errors for syntax. I had to wrap the sections separated by the underscroe with double-quotes and include an '&' :
SQL = "UPDATE tbl_DOM_Bookings SET tbl_Bookings.EmailSent = True WHERE" _
& "(((tbl_Bookings.anBookingID)=" & nBookingNumber & "));"

OTWarrior
07-17-2008, 08:26 AM
An Update Query should never delete records... the closest thing you could do is update the value to empty string.
That's kind of what I thought, as a update query that can also function as a delete query would be lethal. The problem this is the only part of the code that I can see that could possibly change a record.


How do you know that the records are being deleted? Are they no longer in a table, or are they no longer showing on a Form? Could there be a filter that is just keeping them from being seen after they are updated (for instance, are you filtering for tbl_Bookings.EmailSent = True?).

The record is removed from the table. The "anBookingID" is an autonumber, and I am the only one who has the ability to delete records from any table.

Say I have been told by a colleague that there is an error with anBookingID 100. I would look at the table, and records 99 and 101 are there, but 100 isn't.

As for the error in the code, that may be my fault on posting, as it stretched across the screen too much so quickly put in an "_" without thinking of the syntax for actual code.

Thanks for confirming the details about update queries, I will keep looking into why this could be happening.