Solved

Delete Sub in Access

Posted on 2014-03-25
6
218 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:Harry Batt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 39954592
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:Harry Batt
ID: 39954760
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:Harry Batt
ID: 39965639
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:Harry Batt
ID: 39964556
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
ID: 39965519
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:Harry Batt
ID: 39965640
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

624 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