473,749 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2007: Creating a local relationship between two remote ODBCtables

Hi folks, thanks for taking the time to read this (and hopefully point
our where I'm going wrong).

The scenario:

I have a local Access2007 database which links in several read only
mySql tables via ODBC.

The problem:

I need to programmaticall y (in a VBA module) create the relationship
diagram in the access database between the linked tables, just like
you can do in the Relationship editor. (Drag the foreign key of the
child to the primary key in the parent).

For example, say I have two tables: Parents hasMany Children

Parents
id (PK)
Children
id (PK)
parent_id (FK to Parents.id)

So far, I have the following:

Dim r As Relation
Dim ff As Field

Set r = New Relation

With r
.Name = "Parent_Childre n"
.Table = "Children"
.ForeignTable = "Parent"

Set ff = New Field
ff.Name = "parent_id"
ff.ForeignName = "id"

r.Fields.Append ff

CurrentDb.Relat ions.Append r ' *** fails on this line

End With

The error I'm getting is:

Run-time error '3613':

Cannot create a relationship on linked ODBC tables.

Which makes me think access is trying to pass the relationship off to
the (read only) ODBC datasource and not adding it to the local
relations collection.

How do I add it to the local collection (ie, the one used by the
Relationship diagram)?

Thanks in advance
Richard.
Jan 11 '08 #1
10 4453
On Jan 11, 5:10 pm, "Larry Linson" <boun...@localh ost.notwrote:
Relationships define how the database engine deals with the data in the
tables. What would be the purpose in defining relationships in the Access
front end, since they would not be used by your ODBC data source, MySQL?
(For example, if you have a split Access - Jet DB Engine database, you must
define the relationships in the back-end .MDB where the tables actually
reside.)
Yes, the mySql back end also has these relationships defined.

Access is being used as a custom querying/reporting tool by our
client.

To make it easier for them to create their custom queries and reports
I need to populate the access front end relationship diagram so that
when they create new queries, the tables they add will be linked
together correctly in the query gui.

The reason I must do this in code (as opposed to me building the
diagram by hand) is

a) Its quite a complicated schema and I'm bound to miss/mess
something ;-)
b) The schema is under development and quite likely to change before
it's finalised.

So, back to my question: How do I create a relationship diagram in
code :-)
Jan 11 '08 #2

"Richard@Ho me" <ri***********@ gmail.comwrote in message
news:7b******** *************** ***********@k39 g2000hsf.google groups.com...
On Jan 11, 5:10 pm, "Larry Linson" <boun...@localh ost.notwrote:
>Relationship s define how the database engine deals with the data in the
tables. What would be the purpose in defining relationships in the
Access
front end, since they would not be used by your ODBC data source, MySQL?
(For example, if you have a split Access - Jet DB Engine database, you
must
define the relationships in the back-end .MDB where the tables actually
reside.)

Yes, the mySql back end also has these relationships defined.

Access is being used as a custom querying/reporting tool by our
client.

To make it easier for them to create their custom queries and reports
I need to populate the access front end relationship diagram so that
when they create new queries, the tables they add will be linked
together correctly in the query gui.

The reason I must do this in code (as opposed to me building the
diagram by hand) is

a) Its quite a complicated schema and I'm bound to miss/mess
something ;-)
b) The schema is under development and quite likely to change before
it's finalised.

So, back to my question: How do I create a relationship diagram in
code :-)
I have never created a relationship diagram in code and I don't have
available a client-server testbed, but I do have a test database that links
to tables in the example Northwind database.

For previous testing, I created relationships in the front-end between the
pertinent tables in Northwind, and the relationships defined do create join
lines in new Queries. What would happen if you have a difference between
your local relationships (as you might during development, with changes
going on) and the remote relationships, I couldn't say.

And, as I said, I have not created relationships in code, for any type of
tables, so cannot offer worthwhile guidance on that subject.

If I were faced with your problem, I'd create the relationships manually,
and just try to be very careful to "keep on top" of changes that might
affect the relationships; or, if I felt the need was compelling, I would
research at the Microsoft Knowledge Base, http://support.microsoft.com, the
Microsoft Developer Network site,
http://msdn2.microsoft.com/en-us/default.aspx, and do a search using your
favorite search engine.

Good luck with your project,

Larry Linson
Microsoft Access MVP

Jan 11 '08 #3
"Richard@Ho me" <ri***********@ gmail.comwrote in
news:7b******** *************** ***********@k39 g2000hsf.google groups.co
m:
To make it easier for them to create their custom queries and
reports I need to populate the access front end relationship
diagram so that when they create new queries, the tables they add
will be linked together correctly in the query gui.
Two points:

1. you can add non-enforced "relationsh ips" in the relationship
designer that serve no purpose other than defining default joins
between tables.

2. in the QBE, any two tables that have the same field name in both
and appropriate indexes will be joined automatically. My suspicion
is that the MySQL db you're using doesn't use the same name for the
FK as it does for the PK it's related to.

In any event, just define the relationships in your front end and
they'll make building queries easier, which, it seems to me, is what
you're looking for.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 11 '08 #4
"Richard@Ho me" <ri***********@ gmail.comwrote in
news:f4******** *************** ***********@l1g 2000hsa.googleg roups.com
:
In a nutshell, I'm after the code that will create the local
relationship diagram, which I can do manually without generating
the error "Cannot create a relationship on linked ODBC tables."
What is producing that error? I can quite easily create
non-enforeced relationships on ODBC tables (that happen to be MySQL,
in fact) using the user interface for doing so.

Are you sure you're doing it correctly?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 22 '08 #5
Again it may not be eitehr right or wrong but its a lot cleaner and
intuitive.
Naming conventions are a matter of personal preference (in this case,
every CakePHP application follows these conventions), and not really
relevant to my problem :-)
Jan 23 '08 #6
Here's the code again (from my original post).

It's using Microsoft ADO Ext. 2.8 for DDL and Security, I'm quite
happy to change this to another library if that will get the job
done :-)

Dim r As Relation
Dim ff As Field

Set r = New Relation

With r
.Name = "Parent_Childre n"
.Table = "Children"
.ForeignTable = "Parent"

Set ff = New Field
ff.Name = "parent_id"
ff.ForeignName = "id"

r.Fields.Append ff

CurrentDb.Relat ions.Append r ' *** fails on this line

End With

The error I'm getting is:

Run-time error '3613':

Cannot create a relationship on linked ODBC tables.

Thank for taking the time to help out with this :-)
Jan 24 '08 #7
"Richard@Ho me" <ri***********@ gmail.comwrote in news:e4324d0b-559b-
4a************* *******@e10g200 0p...legrou ps.com:
Here's the code again (from my original post).

It's using Microsoft ADO Ext. 2.8 for DDL and Security, I'm quite
happy to change this to another library if that will get the job
done :-)

Dim r As Relation
Dim ff As Field

Set r = New Relation

With r
.Name = "Parent_Childre n"
.Table = "Children"
.ForeignTable = "Parent"

Set ff = New Field
ff.Name = "parent_id"
ff.ForeignName = "id"

r.Fields.Append ff

CurrentDb.Relat ions.Append r ' *** fails on this line

End With

The error I'm getting is:

Run-time error '3613':

Cannot create a relationship on linked ODBC tables.

Thank for taking the time to help out with this :-)
My recollection from the olden days is that one had to create the
relationship with something like

Set r = DbEngine(0)(0). CreateRelation( "NameofRelation ")

then to set the value of its parameters

and then to append it.

Perhaps this is no longer a requirement.

Jan 24 '08 #8
"Richard@Ho me" <ri***********@ gmail.comwrote in
news:e4******** *************** ***********@e10 g2000prf.google groups.co
m:
Here's the code again (from my original post).
[snipped]
It's using Microsoft ADO Ext. 2.8 for DDL and Security, I'm quite
happy to change this to another library if that will get the job
done :-)
Why are you using a generic library to create a structure that is
proprietary to Access? I don't know for a fact that DAO can create
the non-enforced relationship, but it would be the first choice,
since you're altering something in a Jet MDB (i.e., the front end).

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 25 '08 #9
David Wrote:
Why are you using a generic library to create a structure that is
proprietary to Access?
Because it was the first example of code that creates relations that I
found, most of the other example I found used the same libraries (or
referred to the original code I found). I'm a PHP coder by profession
and only use odd bits of Microsoft technologies thrown in when
requested by the client.
I don't know for a fact that DAO can create
the non-enforced relationship, but it would be the first choice,
since you're altering something in a Jet MDB (i.e., the front end).
Ok, no problem. I'm always happy to learn. What technology would you
use in this case? A small snippet of example code would be very useful
too :-)

Lyle wrote:
Set r = DbEngine(0)(0). CreateRelation( "NameofRelation ")
Thank's, I'll take a look at that this morning :-)
Jan 25 '08 #10

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

Similar topics

5
2903
by: steve | last post by:
Hi, I finally figured out the best way to synch local and remote script folders, containing many php script files. What I used to do before was try to ftp all the changed files, etc. which was tedious and often broke. It was also very slow. What I do now is to pkzip the folder up, ftp the pkzip’ed data to remote, and then unzip it there, which recreates the directories and files.
49
4354
by: Allen Browne | last post by:
If you are looking for opinon on what's useful in Access 2007, there's a new article at: http://allenbrowne.com/Access2007.html Covers what's good (useful features), what's mixed (good and bad), what's gone (features removed), what's fixed (old issues solved), what's broken (new bugs), configuration, compatibility, should you buy, and links. It is opinion, so you may disagree, but hopefully it's an informative summary.
4
5483
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available in versions 3.0 or later of the class. However, also just found out that the new Rich Text property in Access 2007 ALSO does not support full text justification! This seems incredible, that MS would create a brand new application, and not...
1
5085
by: Ted Kennedy | last post by:
I have an Access Data Project (.adp) connecting to a SQL Server 2005 DB over the internet. The project has been running in Access 2003 for a couple of years, and performance has been very good. When I convert it to Access 2007 (maintaining the 2002-2003 file format) it gets a LOT slower. It takes about 3-5 seconds just to tab to a new field. Everything seems to work, it's just as if it is moving in molasses. Any ideas on what could be...
0
2699
by: raylopez99 | last post by:
10 years ago, the below was written (see very end, after my signature RL). What, if anything, has changed? I have Access 2003 and soon Access 2007 on a Windows XP Professional or Windows Vista Ultimate machine, with SQL Server Express running on it, and I want somebody, with a password (which I will provide) to be able to log onto a A03 or A07 dB from the internet. Now that I type this I realize that unless I put the database onto a...
3
7751
by: Brett Barry: Go Get Geek! | last post by:
Hello, I just started using Access 2007 after using Access 2003 for a long time. I've created all my queries and they work fine. However, either I forgot or it has changed but, how do I create a report based off of multiple queries? I tried using the report wizard using one query. In the Properties sheet of the report, the record source for the report only shows one query. But if I try and add another text box and add the control
1
3326
by: Jeff | last post by:
I've built a moderately complex table relationship using Access 2007 and back-saving to 2003; my partner on the project has made edits in Access 2003. Today I was unable to open Relationship view using 2007 - crashed the database, prompting to "restart and rebuild" after the crash. Tried: - saving as 2007 (*.accdb) - compact and repair (using both 2003 and 2007) - removing all "subdatasheet" relationships
0
1284
by: musicloverlch | last post by:
I have a database called RADB.mdb. I am working in Access 2007, but have to create a db in Access 2000 as some users don't have Access 2007. Everytime I setup an ODBC link in my database, Access creates a new database in Access 97 version and puts the link there. If I open up one of these databases and try to add another link, it still won't create it in that database! I am getting frustrated. Thanks, Laura
3
1513
by: Edward Gorman | last post by:
Hello Everyone, I'm having abit of difficulty with an aspect of Access. I wish to create a query which changes a persons wage depending upon their age. This is what I have done so far: SELECT Tble_Staff., Tble_Staff., Tble_Staff. AS Normal_Wage FROM Tble_Staff WHERE IIF(=12,13,IIF(=13,13.34,IIF(=14,13.78,IIF(=15,14,IIF(=16,14.50,IIF(=17,14.70,IIF(>=18,15.60,"Invalid Number"))))))); Now, I have the feeling that this doesn't work...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.