Solved

Delete Sub in Access

Posted on 2014-03-25
6
207 Views
Last Modified: 2014-03-30
Hello Experts,

I am trying to create a delete function on a form that gives the user a choice whether to continue. The code I am using doesn't work, but if I just use the DoCmd.RunCommand acCmdDeleteRecord it does work. In both cases I have set the focus to the ProjectID control since there are subforms associated with the main form. What am I doing wrong?
 
Private Sub scmd8_Click()
On Error GoTo err_handle
    Me.ProjectID.SetFocus
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, strAppName) = vbNo Then
    Exit Sub
    Else
    DoCmd.RunCommand acCmdDeleteRecord
    End If

scmd8_ClickExit:
    
   Exit Sub

err_handle:
     
     If Err.Number = 3200 Then
     MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, vbExclamation, "frmProjects"
      End If
            Exit Sub
            
End Sub

Open in new window

0
Comment
Question by:hbatt
  • 4
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
Comment Utility
I can't immediately see anything wrong with your code, but you do have an error handler that only displays a message for Error #3200 (Related records preventing deletion).  Any other error will occur quietly and you won't know.

I suggest you delete lines 16 and 18 and then see if you get a meaningful message.  You could also comment out line 2 while you are debugging.

Graham Mandeno [Access MVP 1996-2014]
0
 

Author Comment

by:hbatt
Comment Utility
Thanks Graham,

I redacted part of the err handle syntax when I submitted my question as it involves writing to an error table, but the problem was with the error handling. I did comment out line 2 and the code worked perfectly.

Thanks for helping me with this code.
0
 

Author Comment

by:hbatt
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for hbatt's comment #a39954760

for the following reason:

Sorry for the delay in awarding points. I thought I had already closed this question.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:hbatt
Comment Utility
Moderator--I believe I closed this question on 3-25 and awarded points to Graham. I don't see that this has happened, but Graham deserves the points.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
Comment Utility
Hi hbatt

Thanks for your intention to select my answer.  I believe you can still accept the answer, but if you close the question it will not be marked as "answered" and no points will be awarded.

I have posted a "Request Attention" to get someone to assist you.

Best wishes,
Graham
0
 

Author Comment

by:hbatt
Comment Utility
Thanks again Graham--I am not sure what that hiccup was, but I know I closed the question and awarded you the points with an "A" score. I did it again and it worked.

Best,

Harry
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now