VBA doesn't work and no errors popup (1 Viewer)

Arcanant

New member
Local time
Today, 09:43
Joined
Jun 4, 2022
Messages
12
I am trying to emulate the "delete" keyboard button in vba to delete a selected record from a subform,
and I am trying to make this happen after running an update Query.

Code:
Private Sub deletebtn_Click()


CurrentDb.Execute ("qrupdateqty")
Call DoCmd.RunCommand(Command:=acCmdDeleteRecord)
Forms!frmCustomers!subfShowSales.Requery
Forms!frmEditSales!subfListProducts.Requery


End Sub


But nothing happens, literally, not even warnings. I tried to do it with DoCmd.RunCommand acCmdDeleteRecord as Access suggests but I am not getting any results.
Any help would be very much appreciated.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:43
Joined
Oct 29, 2018
Messages
21,477
Are you saying no record gets deleted?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:43
Joined
Feb 28, 2001
Messages
27,194
Take the parentheses off the CurrentDB.Execute command. They change the nature of the implied call.

You can also simplify the next line using DoCmd.RunCommand acCmdDeleteRecord as Access documentation suggests. Though syntax-wise, your usage was not wrong. Just maybe a bit wordy.

However, I would not be sure which record would be deleted here. You would be less worried about an ambiguous selection if you could just define a DELETE query to do the selection AND the record deletion simultaneously. What is the SQL of your qrupdateqty query?
 

Arcanant

New member
Local time
Today, 09:43
Joined
Jun 4, 2022
Messages
12
Hello and thanks for your replies.

I actually went ahead and made a Delete Query with criteria and that works for me. Thank you for your attention and replies.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:43
Joined
Sep 21, 2011
Messages
14,317
I just tried that long winded way to delete a record, and received the warning that 1 record is about to be delete?
Is the recordsource even editable?
 

Users who are viewing this thread

Top Bottom