UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Delete Record And Related Records, Access 2016    
 
   
mike60smart
post Jun 1 2019, 10:02 AM
Post#1


UtterAccess VIP
Posts: 13,344
Joined: 6-June 05
From: Dunbar,Scotland


Hi Everyone

I have a Main Form with a Number of Subforms

On The Main Form I am trying to create a Command Button to Delete the Current Record.

I am Using this in the On Click Event:-

[Code]
Private Sub cmdDelete_Click()

On Error GoTo cmdDelete_Click_Error
Dim Answer As Integer

Answer = MsgBox("Are you sure you wish to delete this Case Record?", vbYesNo + vbExclamation + vbDefaultButton2, "Delete Confirmation")
If Answer = vbYes Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True

Else

End If


On Error GoTo 0
Exit Sub

cmdDelete_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdDelete_Click, line " & Erl & "."

End Sub
[\Code]

When I run the code I get the following Error:-

Attached File  error.PNG ( 17.65K )Number of downloads: 0


Hit Debug and it displays the following:-

Attached File  Ticket.JPG ( 14.74K )Number of downloads: 0


Any help appreciated



--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
gemmathehusky
post Jun 1 2019, 11:28 AM
Post#2


UtterAccess VIP
Posts: 4,725
Joined: 5-June 07
From: UK


the docmdmenuitem commandsd were deprecated a long time ago.
They may work, but …

Try

runcommand acCmdDeleteRecord


-----
Your error

I think if you delete the record, it will just show as #deleted in your form, and therefore [feieldname] will have no value
I presume you need to requery the record set after a deletion, before your current record cursor becomes valid.

--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 
mike60smart
post Jun 1 2019, 11:33 AM
Post#3


UtterAccess VIP
Posts: 13,344
Joined: 6-June 05
From: Dunbar,Scotland


Hi Dave

Changed the Code to this:-

[Code]
Private Sub cmdDelete_Click()

On Error GoTo cmdDelete_Click_Error
Dim Answer As Integer

Answer = MsgBox("Are you sure you wish to delete this Case Record?", vbYesNo + vbExclamation + vbDefaultButton2, "Delete Confirmation")
If Answer = vbYes Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True

Else

End If


On Error GoTo 0
Exit Sub

cmdDelete_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdDelete_Click, line " & Erl & "."

End Sub
[\Code]

Still the same outcome?


--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
mike60smart
post Jun 1 2019, 11:40 AM
Post#4


UtterAccess VIP
Posts: 13,344
Joined: 6-June 05
From: Dunbar,Scotland


HiDave

OK Spotted my mistake but have now inserted DoCmd. before the runCommand line

Also move the Form Current Event to the Form's On Load Event and now works a treat

Thanks

cheers.gif

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
gemmathehusky
post Jun 1 2019, 12:19 PM
Post#5


UtterAccess VIP
Posts: 4,725
Joined: 5-June 07
From: UK


I think I use runcommand on it's own

I note there is a runcommand in both

application.runcommand AND
docmd.runcommand

I just tried it in a module, and it seemed to be working with no prefix.



Anyway - pleased you got a solution









--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 
Jeff B.
post Jun 2 2019, 01:00 PM
Post#6


UtterAccess VIP
Posts: 10,275
Joined: 30-April 10
From: Pacific NorthWet


Mike

I'm a bit of a data bigot, so take this with a grain of salt …

When someone (user) says "delete this", often they are (not) saying "I don't want to see it".

Often I'll "delete" a record by end-dating it and having the source only show records that aren't end-dated.

… and that way, when the user says "OMG, I just deleted the wrong record" you get to be a hero by (simply, and when the user isn't looking) removing the end-date... ohyeah.gif


--------------------
Regards

Jeff Boyce
Microsoft Access MVP (2002-2015)

Mention of hardware or software is, in no way, an endorsement thereof. The FTC of the USA made this disclaimer necessary/possible.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    15th September 2019 - 02:46 AM