Deleting strWhere Selection

  • Thread starter Thread starter Sandy
  • Start date Start date
S

Sandy

I have a form that writes a subrecord field value to a
table when opened.

When the user finishes filling out the form they click on
Save.

Once Save is clicked I have the code to ask them if they
want to save. If vbYes, it saves, if VbNo, I want it to
delete the record and close the entry form.

I can get the record to delete with the command toolbar
prompt if I don't have the Docmd.Close in the code. When I
try to delete the record and then close the form it
doesn't delete the record.

Do you have a way to delete a record where the field in
the table matches the field on the open form?

Your assistance is appreciated.

Thanks!

Sandy
 
Hi Sandy,


Providing you delete the record before issuing the Docmd.Close, there should
be no problem. Is that what you're doing?
Also, what happens if the user closes the form without clicking Save? Do
you have code to ask if they want to keep or discard the current record?


Jamie
 
Hi Jamie,

Yes, I'm deleting the record before closing. If the user
chooses vbYes then the form saves and closes.

It's very strange.. I've even tried:

CurrentDb.Execute "DELETE * FROM Table1 WHERE [Field2]='"
& Me.Field2 & "'"

but it doesn't even find the table..

any ideas?

Thanks!

Sandy
 
If it is a new record and has not been saved it cannot be deleted because there
is no record in the table yet. Assuming that you are using a bound form; when
it is closed the data will be automatically written to the table, which is why
you see it as not deleted. To prevent this, use Me.Undo (the equivalent of
pressing Escape twice) in the vbNo section of your form to discard the entered,
but not saved, data.
 
Back
Top