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

conditional delete

Dee
I have a form displaying dealer information.
It contains a subform which displays territories which they are
assigned to this dealer's DealerId number in datasheet view.

I have "delete" disabled on the main form in order to preserve
cascading referential integrity.

I would like to allow deleting the dealer's record, but only if no
territories are assigned to him. This would then preserve referential
integrity.

Using the "before delete" event procedure, I'd like to to display a
message box which asks "This dealer has territories, which will revert
to "unassigned" in the territories table if you proceed!" "Proceed?"

If the answer is "yes" it will run a simple "ReleaseTerritories" query
which I already have.

If the answer is "no" , I simply won't run the "ReleaseTerritories"
query but...

Now comes the tricky part!

I also wish to pass this "No Answer" on to the the "before delete"
event procedure so that it aborts without displaying its yes or no
message query.

Can't seem to get that to work. Anyone have any ideas?
Nov 12 '05 #1
1 1734
You can suppress the display of the warning in Form_BeforeDelConfirm with:
Response = acDataErrContinue

Presumably ReleaseTerritories is an action query that updates DealerID to
Null, so you can delete the dealer and have the territories unassigned? If
so, there may be an even better solution.

JET 4 supports Cascade-to-Null, so it is possible to get Access to do this
for you in Access 2000 or later. The benefit is that it happens at the
engine level - independent of the form events - so works regardless of how
the dealer is deleted.

Unfortunately the interface cannot create nor distinguish this kind of
cascade. ADOX code is the only way. Something like this:

Sub CreateKeyAdox()
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim ky As New ADOX.Key

Set cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblTerritory")

With ky
.Type = adKeyForeign
.Name = "tblDealertblTerritory"
.RelatedTable = "tblDealer"
.Columns.Append "DealerID"
.Columns("DealerID").RelatedColumn = "DealerID"
.DeleteRule = adRISetNull 'Cascade to Null on delete.
End With
tbl.Keys.Append ky

Set ky = Nothing
Set tbl = Nothing
Set cat = Nothing
Debug.Print "Key created."
End Sub

--
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.

"Dee" <wo********@comcast.net> wrote in message
news:35**************************@posting.google.c om...
I have a form displaying dealer information.
It contains a subform which displays territories which they are
assigned to this dealer's DealerId number in datasheet view.

I have "delete" disabled on the main form in order to preserve
cascading referential integrity.

I would like to allow deleting the dealer's record, but only if no
territories are assigned to him. This would then preserve referential
integrity.

Using the "before delete" event procedure, I'd like to to display a
message box which asks "This dealer has territories, which will revert
to "unassigned" in the territories table if you proceed!" "Proceed?"

If the answer is "yes" it will run a simple "ReleaseTerritories" query
which I already have.

If the answer is "no" , I simply won't run the "ReleaseTerritories"
query but...

Now comes the tricky part!

I also wish to pass this "No Answer" on to the the "before delete"
event procedure so that it aborts without displaying its yes or no
message query.

Can't seem to get that to work. Anyone have any ideas?

Nov 12 '05 #2

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

Similar topics

1
by: David Winter | last post by:
(Sorry - couldn't find a generic DocBook NG - I hope this is close enough.) I'm considering moving my documentation and translation business - which is currently done in proprietary formats such...
1
by: Orest Kinasevych | last post by:
Okay, I made sense of the earlier suggestions and realized I was on the right track -- I appreciate the feedback which got me to this point. The suggestions posted here indeed worked and...
28
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
3
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
3
by: JC | last post by:
Hi, I am using a Datagrid and populating it from a database. I have a 'delete' button column, and when click it executes the DeleteCommand event. My problem is I would like this button to...
5
by: Trapulo | last post by:
I'm using conditonal compile with statement #IF CONFIG This works if I use #IF CONFIG = "Debug" or #IF CONFIG= "Release" But if I define an other compilation profile, eg. "BestRelease", and I use...
2
by: Lyn | last post by:
Hi, Having fun trying to get Conditional Formatting working on a textbox control in a continuous form subform (Access 2003). The condition I want is when the value of the textbox is Null and/or...
1
by: Rob | last post by:
Hi, I am using a databound web control (infragistics webgrid) whose dataobject's delete row property is set to run a particular method in the Business Logic Layer. Before calling the Data Access...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.