Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete Sub in Access

Posted on 2014-03-25
6
Medium Priority
?
234 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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

877 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