Solved

VB/Access Referential Integrity

Posted on 2008-10-29
4
228 Views
Last Modified: 2012-05-05
Experts,

I just set up a relationship in Access between two tables that enforces one-to-many referential integrity.  When I tried to delete the parent record from the query window, I was warned that I would leave orphans in the child table, as I should be.

When I run the same query from my VB code, it doesn't delete the parent record (which is good), but it never throws any kind of error telling me I'm about to screw up the database.  Is there any way I can have the VB program let me know when a potential violation of referential integrity is about to take place?
0
Comment
Question by:NigelRocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
ID: 22833619
When you executed the query, the execute function should have at least returned something letting you know that nothing is getting changed.  I know in the case of DAO, the DB.Execute( SQL$ ) function returns a number indicating the number of records modified.
The other possibility might be bad error handling (like an "On Error Resume Next" that is catching any error getting thrown).
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22834068
No error is generated to be caught in "On Error".

As far as the return value on an execute, does anyone know how to do that in ADO?

0
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 500 total points
ID: 22834616
If you are using ADODB (Microsoft ActiveX Data Objects X.X Library),
ADODB.Execute has a parameter for which the number of records affected is passed by reference.

...
Dim RecordsModified as long
Dim DB as ADODB
Dim SQL$
...
DB.Execute( SQL$,RecordsModified, adCmdText )
if RecordsModified = 0 then
    MsgBox "Nothing was modified"
End If
...

Open in new window

0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22891967
I hate to bother you again, but I don't see how this works in ADO.  I don't see that ".execute" has a return value.  What am I missing?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question