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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code behind Command button to delete record 1

Status
Not open for further replies.

THWatson

Technical User
Apr 25, 2000
2,601
0
0
CA
Using Access 2016
Donations part of a church congregation database

If the user wants to Delete a donation for a particular donor, the form is opened, the donor selected, and the record desired for deletion selected.

The user has two choices: (1) press Delete on the keyboard, or (2) press a Delete command button

Behind the command button, called cmdDelete, lies this code
Code:
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

Select Case MsgBox("  Do you really wish to" _
                   & vbCrLf & "   DELETE this record?" _
                   & vbCrLf & "" _
                   & vbCrLf & "This cannot be undone!" _
                   , vbYesNo Or vbExclamation Or vbDefaultButton1, "Delete check")
    Case vbYes
        GoTo DeleteProcess
    Case vbNo
        Exit Sub
End Select
    
DeleteProcess:
    DoCmd.SetWarnings False
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    DoCmd.SetWarnings True

Exit_cmdDelete_Click:
    Exit Sub

Err_cmdDelete_Click:
    MsgBox Err.Description
    Resume Exit_cmdDelete_Click
    
End Sub

This has always worked in the past but doesn't work in Access 2016 (part of the Microsoft Office 365 suite).

Can anyone point me to a way to fix this code?

Thanks!

Tom
 
If envelope 719 has made donations on 20 Sundays during thia year, you will see all of those in rows down the form.

Date, then each category (Local, M&S, Memorial, Building etc.) in a row across the form.

The properties showed Single, but I will change that. It's so long since I designed it.
 
Now I recall you are storing multiple donations in a single record.

I would try create a simple form with the minimal controls and code to test.

First thing would be to fix the table structure.

Duane
Hook'D on Access
MS Access MVP
 
I still don't quite understand why the Delete command button doesn't work...results in an error message saying that "command Delete record" isn't available right now...however, hitting the Delete key works fine.
Tom
 
The selection when using the delete key is definitely in the record. I am thinking the record selection in code doesn't find the correct record. Where was your cursor prior to clicking the delete button?

What is the SQL/record source of the form?

Duane
Hook'D on Access
MS Access MVP
 
Duane
I got this one fixed. I recreated the form, and this one is okay now. Not really sure what was going on, but I'm glad to have it fixed.
Tom
 
Based on "list box is down the left side" AND "you will see all of those in rows down the form" there must have been a single main form and a continuous subform. I know of no other way to have these appear on a standard form:

[pre] +--------------+
| DELETE |
+--------------+

+---------+ +_Label1 Label2 Label3_+
|list | |_____________________________|
| | |_____________________________|
| | |_____________________________|
| | |_____________________________|
| | |_____________________________|
| | |_____________________________|
| |
+---------+
[/pre]


Duane
Hook'D on Access
MS Access MVP
 
Duane
Yes, you are abundantly correct. I did confuse the issue in that regard. (the only excuse I can offer is that I am just recovering from a bout of the shingles and they're nothing to be coveted, really energy-draining)

Anyway, that's no excuse for wasting your time and I sincerely apologize. I don't know what was wrong with me that I didn't figure that out yesterday. A forest-trees thing maybe.

In recreating, I moved the DELETE command button from the main form to the subform, and that, I believe, was the issue from the outset. I need to check with the user, the church secretary, but I suspect it hasn't worked for a while and she just didn't tell me.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top