Solved

Delete Sub in Access

Posted on 2014-03-25
6
212 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
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:hbatt
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:hbatt
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:hbatt
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:hbatt
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

828 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