Solved

VB/Access Referential Integrity

Posted on 2008-10-29
4
225 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now