Solved

VB/Access Referential Integrity

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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