"Crash" when deleting a row from a subform

G

Guest

I have a form with a subform in it. The subform has two button on it to add
or delete records. The add button has a little code in it to set up some
defaults. The delete button consists entirely of this code:

Private Sub DeleteRow_Click()
Me.Recordset.Delete
Me.Recordset.Update
Me.Refresh
End Sub

This code randomly causes the machine to "go away" and never return, only a
force quit will return control. There does not appear to be a hidden dialog
or anything like that. It seems to happen 100% of the time on certain
machines and never on others, but I'm not certain of that.

Any ideas?

Maury
 
J

John W. Vinson

I have a form with a subform in it. The subform has two button on it to add
or delete records. The add button has a little code in it to set up some
defaults. The delete button consists entirely of this code:

Private Sub DeleteRow_Click()
Me.Recordset.Delete
Me.Recordset.Update
Me.Refresh
End Sub

This code randomly causes the machine to "go away" and never return, only a
force quit will return control. There does not appear to be a hidden dialog
or anything like that. It seems to happen 100% of the time on certain
machines and never on others, but I'm not certain of that.

Any ideas?

Maury

HUH!?

You're not deleting a row from the table.

You're deleting the FORM'S Recordset.

I'm rather surprised it even runs, but not very surprised that it
crashes Access.

I'd replace the two Me.Recordset lines with

DoCmd.RunCommand acCmdDeleteRecord

John W. Vinson [MVP]
 
R

RoyVidar

Maury Markowitz said:
I have a form with a subform in it. The subform has two button on it
to add or delete records. The add button has a little code in it to
set up some defaults. The delete button consists entirely of this
code:

Private Sub DeleteRow_Click()
Me.Recordset.Delete
Me.Recordset.Update
Me.Refresh
End Sub

This code randomly causes the machine to "go away" and never return,
only a force quit will return control. There does not appear to be a
hidden dialog or anything like that. It seems to happen 100% of the
time on certain machines and never on others, but I'm not certain of
that.

Any ideas?

Maury

I'm no perticular fan of the .Delete method of the recordset, but it
should work to delete the current recor. You can try what John Vinson
suggested

DoCmd.RunCommand acCmdDeleteRecord

or try to delete through a query

CurrentDB.Execute "DELETE FROM myTable WHERE id = " & _
Me!txtPK, dbFailOnError
Me.Requery

But I think it is possible that this crashing stems from a corruption.

I would try either importing all objects into a new database or
try /decompile on a copy of the db - for the latter, see the step by
step instructions here
http://www.granite.ab.ca/access/decompile.htm
 
G

Guest

John W. Vinson said:
HUH!?

You're not deleting a row from the table.

You're deleting the FORM'S Recordset.

Sure, but doesn't that end up deleting from the table? If it doesn't, what's
the purpose of the delete method?
I'd replace the two Me.Recordset lines with

DoCmd.RunCommand acCmdDeleteRecord

Ok thanks, I'll give it a try and let you know!

Maury
 
J

John W. Vinson

Sure, but doesn't that end up deleting from the table? If it doesn't, what's
the purpose of the delete method?

I've never used the Delete Method in this way; but what your code
would do has nothing whatsoever to do with deleting *a record* out of
a Recordset.

The Form's Recordset is the complete set of all the records in the
Query upon which the form is based. Your code was not taking one egg
out of that crate of eggs; it was throwing the entire crate into the
dumpster.

John W. Vinson [MVP]
 
G

Guest

John W. Vinson said:
The Form's Recordset is the complete set of all the records in the
Query upon which the form is based. Your code was not taking one egg
out of that crate of eggs; it was throwing the entire crate into the
dumpster.

Oh, I see what you're saying now.

Are you sure about this? It doesn't seem right. Like I said, this method
works fine on the majority of machines it's run on. In fact, when it failed
last time I simply walked over to my machine, pressed the same button, and
presto.

Maury
 

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

Top