473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Warning user of record deletion

Hi,

I need help creating a dialog box. Basically I have a delete record button in my DB, but when clicked, I want a dialog box popping up saying something like "Are you sure you want to delete this record?"

So Im guessing Im going to need some sort of "IF" statement when the button is clicked...but im lost since I dont know much about programming. If anybody could help I would appreciate it.

Thanks,

Rob
Sep 1 '08 #1
8 4840
yaaara
77
You may use something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim vChoice as String
  2. vChoice = MsgBox("Are you sure you want to delete?", vbQuestion, "Confirm")
  3. If vChoice = vbYes Then
  4.    'Proceed further
  5. Else
  6.     Exit Sub
  7. End If
Sep 1 '08 #2
missinglinq
3,532 Expert 2GB
Line #2 of that code needs to be changed from

vChoice = MsgBox("Are you sure you want to delete?", vbQuestion, "Confirm")

to

vChoice = MsgBox("Are you sure you want to delete?", vbQuestion + vbYesNo, "Confirm")

When vbQuestion is used by itself, a single "Okay" button appears, so the user has no real choice. And since clicking "Okay" doesn't return vbYes, the code will branch to the Else statement and the deletion will never happen.

The Dim statement, if used, should really be

Dim vChoice as Integer

as that's what message boxes actually return. vbYes is a Constant for 6 and vbNo is a Constant for 7. Fortunately, Access is very forgiving in this, and reads the String 6 or 7 as a number.

Welcome to Bytes!

Linq ;0)>
Sep 1 '08 #3
Thanks both of you. Works just like I want it. Much Appreciated
Sep 1 '08 #4
ADezii
8,834 Expert 8TB
Thanks both of you. Works just like I want it. Much Appreciated
There is only 1 major problem with the previous approach. What if a User Deletes a Record via the Menu Bar or Toolbar? The following code, placed in the BeforeDelConfirm() Event, will cover all contingencies:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
  2. Dim intResponse As Integer
  3.  
  4. 'Suppress the Access Delete Confirmation Dialog Box, do not
  5. 'prompt the User
  6. Response = acDataErrContinue
  7.  
  8. 'Display your own Custom Delete Dialog Box
  9. intResponse = MsgBox("Delete Record(s)?", vbQuestion + vbYesNo + vbDefaultButton1, _
  10.                      "Record(s) Deletion")
  11.  
  12. If intResponse = vbYes Then
  13.   'do nothing and just fall through
  14. Else
  15.   Cancel = True     'Cancel the Deletion (don't Delete Record(s))
  16. End If
  17. End Sub
Sep 1 '08 #5
It would be very good to have a warning through using the toolbar or menu.

The code doesnt seem to work though?
Sep 2 '08 #6
ADezii
8,834 Expert 8TB
It would be very good to have a warning through using the toolbar or menu.

The code doesnt seem to work though?
What exactly is the error you are getting?
Sep 2 '08 #7
What exactly is the error you are getting?

No Error, it just deletes the record without asking a dialog box.

Its like its not executing Form_BeforeDelConfirm. The code is there but not being used
Sep 2 '08 #8
ADezii
8,834 Expert 8TB
No Error, it just deletes the record without asking a dialog box.

Its like its not executing Form_BeforeDelConfirm. The code is there but not being used
The code is sound and fully functional. There are only 3 reasons that I can think of as to why it isn't working for you:
  1. The code is not in the BeforeDelConfirm() Event Procedure of the Form.
  2. The code is in the correct Procedure, but it is not the exact code that I had previously posted.
  3. The words [Event Procedure] do not exist in the Before Del Confirm Property of the Form.
Sep 2 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve | last post by:
I'm working in PHP, but am also using JavaScript, so perhaps there is a better way to do this using more PHP code...... I setup a search screen for my database, the user enters data and submits...
3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
40
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might...
6
by: Tom McL. | last post by:
I'm trying to move a program that was designed using Visual Studio 2003 and (Visual Basic) into Visual Studio 2005. When it runs I get the following warning in the Error List Window and I'm not...
6
by: No Spam | last post by:
Dear Access 2003 Users, Is there a way to pop up a MessageBox warning when a user changes data on a form? Basically, I have one field that I really want people to think about before changing,...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
2
by: Andy.I | last post by:
Hi I have a small aplication that stores data in a random access file. I'm able to modify records, and add new records. But how can I delete a certain record and remove it enirely from the file?...
4
by: Phil Stanton | last post by:
Sorry to repost, but am having another look at deleting a record. I have a form (Member) and have removed all the event procedures associated with the Form (OnCurrent, OnDelete, OnActivate etc)...
11
by: Jeff | last post by:
I turned on errors in php: ini_set('display_errors','1'); And I got a slew of notices and a couple of warnings. The notices are mostly missing indexes from doing things like this: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.