473,395 Members | 1,977 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,395 software developers and data experts.

Execute dbFailonError & Cascade Delete

HI all, Access 2003, Jet back end.

Rather than annoy my users in a particular app by having relationships
with enforced relational integrity refuse to delete a record with
related records, I'm using cascade delete. When I use a continuous form
and a record is deleted, Access provides a warning that there are
related records, do you want to continue (an aside - anyone know how to
trap that warning on the form on error event?). However, when I
construct SQL dynamically in VBA, say a string, strSql where strSql is
of the form "delete * from tbl_Whatever Where blah blah", and run:

DatabaseObject.Execute strSql, dbfailonerror

The warning about related records is not fired. In fact, it explicitly
says so in the help file that the warning will not be fired in this case.

So, what I've done in a couple of instances is simply make sure I know
what the relationships are with respect to the table in question and run
some DAO recordsets to see if there any related records and warn the
user when they press the button that fires the execute statement before
the button on click event gos ahead and constructs the delete statement.

This is sometimes rather arduous, especially in development where an app
may be frequently modified and more tables and more relationships added
later after launch or even throughout initial development and I'm
wondering if anyone has done anything that might be simpler.

Thanks in advance for any ideas.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #1
3 3872
Tim Marshall wrote:
HI all, Access 2003, Jet back end.

Rather than annoy my users in a particular app by having relationships
with enforced relational integrity refuse to delete a record with
related records, I'm using cascade delete. When I use a continuous form
and a record is deleted, Access provides a warning that there are
related records, do you want to continue (an aside - anyone know how to
trap that warning on the form on error event?). However, when I
construct SQL dynamically in VBA, say a string, strSql where strSql is
of the form "delete * from tbl_Whatever Where blah blah", and run:

DatabaseObject.Execute strSql, dbfailonerror

The warning about related records is not fired. In fact, it explicitly
says so in the help file that the warning will not be fired in this case.

So, what I've done in a couple of instances is simply make sure I know
what the relationships are with respect to the table in question and run
some DAO recordsets to see if there any related records and warn the
user when they press the button that fires the execute statement before
the button on click event gos ahead and constructs the delete statement.

This is sometimes rather arduous, especially in development where an app
may be frequently modified and more tables and more relationships added
later after launch or even throughout initial development and I'm
wondering if anyone has done anything that might be simpler.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

When running an SQL Delete command I know before-hand which tables are
going to be affected by the Cascade Deletes so I just give a generic
MsgBox warning - just as Access does in a Form delete. Access doesn't
check to see if there are any related records, it only sees that there
is a Cascade Delete requirement on the relationship and gives its
"related records" warning.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQwJKrIechKqOuFEgEQLlaQCfVTALgTtbEw5KojCxRmijiT qU/b4AoJuf
3k53/vm/V9u19B+RbTY3mp7a
=fylS
-----END PGP SIGNATURE-----
Nov 13 '05 #2
Tim, you could do the same as MG Foster suggests: check to see if there are
any other tables that have a relation with the one you are deleting from,
and if so, whether those relations involve a cascading delete.

This kind of thing:

Function HasDeleteCascade(strTable As String) As Boolean
Dim db As DAO.Database
Dim rel As DAO.Relation

Set db = CurrentDb()
For Each rel In db.Relations
If rel.Table = strTable Then
If (rel.Attributes And dbRelationDeleteCascade) > 0 Then
Debug.Print rel.ForeignTable
HasDeleteCascade = True
Exit For
End If
End If
Next

Set rel = Nothing
Set db = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MGFoster" <me@privacy.com> wrote in message
news:LU*****************@newsread2.news.pas.earthl ink.net...
Tim Marshall wrote:
HI all, Access 2003, Jet back end.

Rather than annoy my users in a particular app by having relationships
with enforced relational integrity refuse to delete a record with related
records, I'm using cascade delete. When I use a continuous form and a
record is deleted, Access provides a warning that there are related
records, do you want to continue (an aside - anyone know how to trap that
warning on the form on error event?). However, when I construct SQL
dynamically in VBA, say a string, strSql where strSql is of the form
"delete * from tbl_Whatever Where blah blah", and run:

DatabaseObject.Execute strSql, dbfailonerror

The warning about related records is not fired. In fact, it explicitly
says so in the help file that the warning will not be fired in this case.

So, what I've done in a couple of instances is simply make sure I know
what the relationships are with respect to the table in question and run
some DAO recordsets to see if there any related records and warn the user
when they press the button that fires the execute statement before the
button on click event gos ahead and constructs the delete statement.

This is sometimes rather arduous, especially in development where an app
may be frequently modified and more tables and more relationships added
later after launch or even throughout initial development and I'm
wondering if anyone has done anything that might be simpler.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

When running an SQL Delete command I know before-hand which tables are
going to be affected by the Cascade Deletes so I just give a generic
MsgBox warning - just as Access does in a Form delete. Access doesn't
check to see if there are any related records, it only sees that there
is a Cascade Delete requirement on the relationship and gives its
"related records" warning.

Nov 13 '05 #3
On Tue, 16 Aug 2005 05:31:20 -0230, Tim Marshall
<TI****@PurplePandaChasers.Moertherium> wrote:
(an aside - anyone know how to
trap that warning on the form on error event?).


IIRC, that's not an error; it's a preference. Take a look at the
options that control confirmation. (Tools | Options, something like an
"edit" tab, something to do with record changes.)

If it's a user preference, you should probably save the preference when
your app opens, and restore it when your app exits.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
4
by: Robert | last post by:
What is the syntax to use in a VBA script to execute a pass-through? Thanx
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
2
by: nekiv90 | last post by:
Greetings, I have to delete older policies and its related records in other tables. The deletion from the parent table will trigger the deletion of relevant records from about 30 something...
3
by: codeman | last post by:
Hi all Lets say we have two tables: Customer: Customer_number : Decimal(15) Name : Char(30) Purchase: Purchase_number : Decimal(15)
4
by: gmazza | last post by:
Hi there, I am trying to insert 4 fields into a table grabbing the 4 fields from a form, here is my code: Private Sub LastPaymentAmount_AfterUpdate() Dim CurrentProject As DAO.Database Set...
0
by: ShirishKumar | last post by:
I have three tables 1) Country - columns (PKCountryId(PrimaryKey),CountryName) 2)State - Columns (PKStateId(PrimaryKey),StateName,FKCountryId(ForeignKey)) 3)Address Details...
1
by: natural | last post by:
Good Morning I have an unbound form "FrmInterviewSuccesfful" with some unbound fields on it There is also an option box with 3 options and by clicking on it my subform wil filter with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.