Trying to delete a record with code

Jon123

Registered User.
Local time
Today, 00:04
Joined
Aug 29, 2003
Messages
668
Why does this code not delete the current record?

DoCmd.RunSQL "DELETE * FROM [Tble-Readings]WHERE
[Tble-Readings].[ID]= " & Me![ID] & ";"

I have this code on the a Close Button and if the record is incomplete I want it to be deleted from the table. The ID field is an autonumber so it is the 1st field to get a value if a user starts entering data. I get a msg box saying 0 fileds will be deleted why? the id's do match but it does not delete??

jon
 
Hi jon -

My guess is that the button works on a previously entered record, but not on a new one.

If so, then what you are seeing is the fact that Access doesn't actually write a new record until you move to another record, or close the form.

You could do something like:
DoCmd.Close acForm, Me.Name, acSaveNo

Of course that will close the form, which you may not want to do. There is probably also someway to return to the previous record, but I would have to look into it.

hth,

- g
 
Jon:

If your goal is to eliminate the record if it's incomplete when entered, have you considered using the "undo" method instead?

SHADOW
 
Thanks, Shadow. That's the other thing I was trying to remember.
 

Users who are viewing this thread

Back
Top Bottom