Delete Record from Command Button

  • Thread starter ladybug via AccessMonster.com
  • Start date
L

ladybug via AccessMonster.com

I have a command button in a subform. The subform is set to continuous. I
have this in the OnClick Event Procedure:

DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE * FROM dbo_sds_dir_route WHERE RouteID = forms!rm_route!
sfrm_route_work_outs!txt_routeid;")
Me.Requery

I want when the button is clicked the corresponding entry on the continuous
subform is deleted. Can someone help me? This code is not deleting the
record.
 
V

Vincent Verheul

You may try something like this:

Private Sub DelButton_Click()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
If Not rs.AbosolutePosition = -1 Then rs.Delete
Set rs = Nothing
End Sub

Assuming that your the delete button is called DelButton, this routine is
invoked when you click on it.
 
L

ladybug via AccessMonster.com

I tried that and I recvd a Compile Error and it highlighted Absolute Position

Vincent said:
You may try something like this:

Private Sub DelButton_Click()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
If Not rs.AbosolutePosition = -1 Then rs.Delete
Set rs = Nothing
End Sub

Assuming that your the delete button is called DelButton, this routine is
invoked when you click on it.
I have a command button in a subform. The subform is set to continuous. I
have this in the OnClick Event Procedure:
[quoted text clipped - 9 lines]
subform is deleted. Can someone help me? This code is not deleting the
record.
 
V

Vincent Verheul

AbosolutePosition is ONE word


ladybug via AccessMonster.com said:
I tried that and I recvd a Compile Error and it highlighted Absolute
Position

Vincent said:
You may try something like this:

Private Sub DelButton_Click()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
If Not rs.AbosolutePosition = -1 Then rs.Delete
Set rs = Nothing
End Sub

Assuming that your the delete button is called DelButton, this routine is
invoked when you click on it.
I have a command button in a subform. The subform is set to continuous.
I
have this in the OnClick Event Procedure:
[quoted text clipped - 9 lines]
subform is deleted. Can someone help me? This code is not deleting the
record.
 
L

ladybug via AccessMonster.com

Sorry I had it correct in the code. I did not mean to put a space in my
comment above. I received the error from your code as is.

Vincent said:
AbosolutePosition is ONE word
I tried that and I recvd a Compile Error and it highlighted Absolute
Position
[quoted text clipped - 17 lines]
 
V

Vincent Verheul

There was a typo in my code example: it says AbOsolutePosition which should
have been AbsolutePosition


Vincent Verheul said:
AbosolutePosition is ONE word


ladybug via AccessMonster.com said:
I tried that and I recvd a Compile Error and it highlighted Absolute
Position

Vincent said:
You may try something like this:

Private Sub DelButton_Click()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
If Not rs.AbosolutePosition = -1 Then rs.Delete
Set rs = Nothing
End Sub

Assuming that your the delete button is called DelButton, this routine is
invoked when you click on it.

I have a command button in a subform. The subform is set to continuous.
I
have this in the OnClick Event Procedure:
[quoted text clipped - 9 lines]
subform is deleted. Can someone help me? This code is not deleting
the
record.
 
L

ladybug via AccessMonster.com

Perfect! One thing I did notice. It will only let me remove one record at
a time.

Once I click the button the record is deleted. If I select another record
and click the button nothing happens. If I close the form and then open it,
I can then click the button and remove the second record. Is there somewhere
in the code that I can refresh or something? Thank you for all your help!

Vincent said:
There was a typo in my code example: it says AbOsolutePosition which should
have been AbsolutePosition
AbosolutePosition is ONE word
[quoted text clipped - 20 lines]
 
V

Vincent Verheul

When you add a Command button and use the Wizzard to create a 'Delete
Record' button you'll get the following code:

Private Sub DelRec_Click()
On Error GoTo Err_DelRec_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

Exit_DelRec_Click:
Exit Sub

Err_DelRec_Click:
MsgBox Err.Description
Resume Exit_DelRec_Click
End Sub


That works fine on my computer, also with multiple deletes after another
without having to close the form.



ladybug via AccessMonster.com said:
Perfect! One thing I did notice. It will only let me remove one record
at
a time.

Once I click the button the record is deleted. If I select another record
and click the button nothing happens. If I close the form and then open
it,
I can then click the button and remove the second record. Is there
somewhere
in the code that I can refresh or something? Thank you for all your help!

Vincent said:
There was a typo in my code example: it says AbOsolutePosition which
should
have been AbsolutePosition
AbosolutePosition is ONE word
[quoted text clipped - 20 lines]
the
record.
 

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