Substituting my own MsgBox for the standard delete confirm MsgBox

J

John S. Ford, MD

I have a form with some code that allows the user to hit a command button
that deletes the current record. Access routinely asks the user to confirm
that they wish to delete the record.

My questions...can I substitute the standard Access message with my own?
How would I do this? It's not an "error" so I wouldn't think writing my own
error handler would do the trick.

John
 
A

Arvin Meyer

You can use a standard message box, but with your own button configuration,
or a custom form built like a message box which can also allow you to use a
custom function with the "message box".

First, there are 2 ways that you can achieve usage of the message box, the
statement, and the function. Examples:

Statement:
MsgBox "Hello World!", vbOKOnly, "Test Example"

Function(Example from Access 97 Help):
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.

MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If

A custom MsgBox is available on my website, convertable to any version of
Access:

http://www.datastrat.com/Download/MsgBox2K.zip
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Douglas J. Steele

I think John's question is more "How can I intercept the event that prompts
the user whether they want to delete?"

I'm not sure you can intercept that prompt, but you can turn it off using
DoCmd.SetWarnings False, or you can use the Execute method to run SQL to do
the delete. If you're turning off the warnings, make sure to turn them back
on when you're done.
 
J

John S. Ford, MD

Right Doug,

I know I can turn the warning off. I was trying to substitute my own
warning. Some users won't even know what a "record" is. They will know
what a "Patient" is though and I'd like the warning to reflect that.

John
 
D

Douglas J. Steele

So turn the warning off, and display your own message box before you
actually do the delete.

I've built applications where I've taken it further than that. To ensure RI,
I've written my own queries to determine whether I can delete records
because of existing child records (or whether there are child records that
will be cascade deleted) and told the users that in my message box before
I've even attempted to do the delete.
 
V

Van T. Dinh

Code your CommandButton_Click Event to show your own MsgBox. Use the result
of the MsgBox to proceed with the deletion or not. Something

****Untested****
Private Sub Command_Click()
Dim intResponse As Integer
intResponse = MsgBox("Delete Patient?", vbYesNo + _
vbDefaultButton2 + vbQuestion, "Confirm Deletion?")
If intResponse = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings False
End If
End Sub
********
 
A

Arvin Meyer

You may want to take a look at the BeforeDelConfirm event which can be
cancelled should you decide not to delete the record. If it is cancelled,
the warning message won't appear. If not, you can SetWarnings False and
proceed with the deletion.

I never allow most users to delete records, so I haven't spent much time
working with these events. My preference is to mark records to not be
displayed, then requery the recordsource so that the "deleted" record is no
longer seen. It's more trouble in the beginning, but far less than having a
clueless user (or worse, a malicious user) run amok in the database.

BTW, I see the word "Patient" and notice that you are an MD, so I am
assuming that you are building a medical database. Access security must be
strictly adhered to to achieve compliance with HIPPA laws. It is important,
that you spend adequate time teaching your users what a "record" is and the
nuances of patient privacy, as well as protection of the personal financial
information. When you are nearing completion of your project, be sure to get
a security audit to make sure you and your patients are protected.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access Downloads
http://www.datastrat.com
http://www.mvps.org/access
 
J

John S. Ford, MD

Arvin,

You have no idea of the hurdles we're going through with the HIPPA
Guidelines! The people who will be using this database are ALL physicians
(residents and interns actually) and are intimately aware of these rules.
Trust me, the IS people at our facility who will be responsible for
deploying the database hospital-wide are also fully aware of it as well.
Lots and lots of committees!

John
 
A

Arvin Meyer

Since I am both a database developer and a security consultant, I am well
aware of the hoops you are being forced to jump through. In my experience,
the biggest obstacle to easy HIPPA compliance are the insurance companies.
They are convinced that their databases and their procedures help them
eliminate fraud. Were I a crook, I'd be in bed with the insurance companies
because their insistence on data collection is the biggest contributor to
the proliferation of fraud there is.

The medical professions must now walk a very narrow line between legal
compliance and providing insurance companies with the data they desire
before they will pay. I don't envy your position at all.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top