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
8 4840
You may use something like this: -
Dim vChoice as String
-
vChoice = MsgBox("Are you sure you want to delete?", vbQuestion, "Confirm")
-
If vChoice = vbYes Then
-
'Proceed further
-
Else
-
Exit Sub
-
End If
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)>
Thanks both of you. Works just like I want it. Much Appreciated
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: - Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
-
Dim intResponse As Integer
-
-
'Suppress the Access Delete Confirmation Dialog Box, do not
-
'prompt the User
-
Response = acDataErrContinue
-
-
'Display your own Custom Delete Dialog Box
-
intResponse = MsgBox("Delete Record(s)?", vbQuestion + vbYesNo + vbDefaultButton1, _
-
"Record(s) Deletion")
-
-
If intResponse = vbYes Then
-
'do nothing and just fall through
-
Else
-
Cancel = True 'Cancel the Deletion (don't Delete Record(s))
-
End If
-
End Sub
It would be very good to have a warning through using the toolbar or menu.
The code doesnt seem to work though?
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?
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
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: - The code is not in the BeforeDelConfirm() Event Procedure of the Form.
- The code is in the correct Procedure, but it is not the exact code that I had previously posted.
- The words [Event Procedure] do not exist in the Before Del Confirm Property of the Form.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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?...
|
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)...
|
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:
...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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....
|
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
|
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...
|
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...
| |