Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why can't I delete a new record?

Status
Not open for further replies.

edowling

Technical User
Nov 17, 2000
12
US
I have a form with a "Delete" button on top. I want this button to delete the current record and then close the form after. I have created a SQL string that runs to delete the current record:

DELETE [EnrollmentTable].* FROM [EnrollmentTable] WHERE [StudentID]=[Forms]![EnrollmentForm]![StudentID]

The problem I'm having is that if the user has begun to type in a new record and then decides that she/he has screwed up and wants to delete the record, the delete button doesn't actually delete anything.

Any suggestions?

Lis
 
Im not sure but perhaps it may have something to do with the focus. maybe because after the user has started to enter info. the focus is on one field, instead of the record as a whole, which may explain why. another easy way to do this is to add a delete button using the toolbox cmdbutton wizard to make a delete record button, then go into the module and add a line of code right after the delete line to close the form. docmd.close acform, "yourformname" maybe this will help
 
When someone starts to type something, the record does not exist. Not until you save it. If you set the forms IsDirty property to false, I believe it will do wahta you are asking. You may want to null out the fields that have been typed into.

If you do a search in this forum or in Ms. Access Help for the IsDirty property, you should get a good example... Terry M. Hoey

Please read the following FAQ to learn how to help me help you...

faq183-874
 
Okay, I tried searching for IsDirty in the forum and I only got 3 records that use it in passing. I searched in Ms Access and there was only 1 example that I didn't really understand (it was under Dirty Property, nothing about IsDirty). Can you give me a little more information? I've tried almost everything to make this work and I'm getting a bit desparate.

Thanks,

Lis
 
Like I mentioned in the other post, at this point in time, there is no record to delete. All you have is data on a form. I gather you have a close button on your form. You could place code in the button click event of the close button that would prompt the user if they wanted to save the record or not. Something like:

Private Sub btnClose_Click()
Dim retval as integer

If Me.Dirty then
If MsgBox("Do you want to save?", vbOKCancel, "Error!") = vbOK then
DoCmd.Close acForm, "MyForm", acSaveYes
else
DoCmd.Close acForm, "MyForm", acSaveNo
endif
else
DoCmd.Close acForm, "MyForm", acSaveNo
end if
End Sub

I didn't test this, but it should work.
Terry M. Hoey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top