Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete Sub in Access

Posted on 2014-03-25
6
Medium Priority
?
227 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

705 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