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

Creating ODBC table links

Hi all,
I'm having quite a bit of trouble with code to create linked tables in
Access 2K. I create a DAO tabledef using CreateTableDef against a DAO
database object, then set its connection string appropriately. The
trouble is when I go to append the tableDef to the collection I get
error 3264:
No field defined --cannot append TableDef or Index

Any suggestions?

Many thanks,

Eric

Code follows:
Public Function LinkAllTables()
' Link all tables

Dim rstTableNames As New ADODB.Recordset
Dim sGetTableNamesSQL As String, sConnStr As String

' SQL to read the list of tablenames
sGetTableNamesSQL = "SELECT DISTINCT table_name, table_schema FROM
information_schema.table_privileges " _
& " WHERE table_schema <> 'information_schema' and table_schema
<>'pg_catalog' " _
& " ORDER BY table_name; "
Dim tdf As DAO.TableDef
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).Databases(0)
With rstTableNames
Set .ActiveConnection = GetPGConnStr
.LockType = adLockReadOnly
.CursorLocation = adUseServer
.Source = sGetTableNamesSQL
.Open
While Not .EOF
Set tdf = db.CreateTableDef(.Fields("table_name"), , _
.Fields("table_schema") & "." & .Fields("table_name"))

tdf.Connect = GetPGConnStr
'tdf.Attributes = dbAttachedODBC
db.TableDefs.Append tdf
.MoveNext
Wend
End With
End Function

Public Function GetPGConnStr() As String
GetPGConnStr =
"ODBC;DSN=lims;DRIVER=PostgreSQL;SERVER=localhost; PORT=5432;"
End Function
Nov 13 '05 #1
4 13450
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The error you are getting is saying that the defined table needs the
columns (aka Fields ) defined that go w/ that table. IOW, you need the
full meta-definition of that table (columns, unique indexes, primary
keys) to "re-construct" it as an Access linked table.

To link ODBC tables it is easier to run the TransferDatabase method of
the DoCmd object. Unfortunately, if the tables don't have unique
indexes/primary keys defined you will be prompted for those fields when
you run the TransferDatabase method.

When that happens - what I've done is just Escape thru the pop-up prompt
& run a DDL statement (in an Access query) that adds the index/PK
constraints.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQaFTfoechKqOuFEgEQKubwCfZgMiBhgSzCwqZ86plPS5gw aewAoAn3yu
uxwo3tBk2d1gVQaRjXRhAdHv
=hRBs
-----END PGP SIGNATURE-----
Eric E wrote:
Hi all,
I'm having quite a bit of trouble with code to create linked tables
in Access 2K. I create a DAO tabledef using CreateTableDef against a
DAO database object, then set its connection string appropriately. The
trouble is when I go to append the tableDef to the collection I get
error 3264:
No field defined --cannot append TableDef or Index

Any suggestions?

Code follows:
Public Function LinkAllTables()
' Link all tables

Dim rstTableNames As New ADODB.Recordset
Dim sGetTableNamesSQL As String, sConnStr As String

' SQL to read the list of tablenames
sGetTableNamesSQL = "SELECT DISTINCT table_name, table_schema FROM
information_schema.table_privileges " _
& " WHERE table_schema <> 'information_schema' and table_schema
<>'pg_catalog' " _
& " ORDER BY table_name; "
Dim tdf As DAO.TableDef
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).Databases(0)
With rstTableNames
Set .ActiveConnection = GetPGConnStr
.LockType = adLockReadOnly
.CursorLocation = adUseServer
.Source = sGetTableNamesSQL
.Open
While Not .EOF
Set tdf = db.CreateTableDef(.Fields("table_name"), , _
.Fields("table_schema") & "." & .Fields("table_name"))

tdf.Connect = GetPGConnStr
'tdf.Attributes = dbAttachedODBC
db.TableDefs.Append tdf
.MoveNext
Wend
End With
End Function

Public Function GetPGConnStr() As String
GetPGConnStr =
"ODBC;DSN=lims;DRIVER=PostgreSQL;SERVER=localhost; PORT=5432;"
End Function

Nov 13 '05 #2
Hi,
Many, many thanks for the tip. The TransferDatabase method works well,
and, as you predicted, linking to tables/view that don't expose a
primary key produces the same popup that occurs when using the table
linking wizard. Is there any way I can pass a SendKeys argument to
automatically hit ESC in these cases?

Thanks,

EE
MGFoster wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The error you are getting is saying that the defined table needs the
columns (aka Fields ) defined that go w/ that table. IOW, you need the
full meta-definition of that table (columns, unique indexes, primary
keys) to "re-construct" it as an Access linked table.

To link ODBC tables it is easier to run the TransferDatabase method of
the DoCmd object. Unfortunately, if the tables don't have unique
indexes/primary keys defined you will be prompted for those fields when
you run the TransferDatabase method.

When that happens - what I've done is just Escape thru the pop-up prompt
& run a DDL statement (in an Access query) that adds the index/PK
constraints.

Nov 13 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SendKyes -> Esc? Not that I know of. Since I consider linking ODBC
tables & views a developing/Administrator event I don't make it user
friendly. It's just a subroutine I run thru the debug window.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQaKg7oechKqOuFEgEQJTAgCeMcb8oXQQPv109aoxY9GrSn WjSoIAoOvF
NuqNNjTKfTTfRyVuLMdUNy+9
=nz3F
-----END PGP SIGNATURE-----

Eric E wrote:
Hi,
Many, many thanks for the tip. The TransferDatabase method works
well, and, as you predicted, linking to tables/view that don't expose a
primary key produces the same popup that occurs when using the table
linking wizard. Is there any way I can pass a SendKeys argument to
automatically hit ESC in these cases?

Thanks,

EE
MGFoster wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The error you are getting is saying that the defined table needs the
columns (aka Fields ) defined that go w/ that table. IOW, you need the
full meta-definition of that table (columns, unique indexes, primary
keys) to "re-construct" it as an Access linked table.

To link ODBC tables it is easier to run the TransferDatabase method of
the DoCmd object. Unfortunately, if the tables don't have unique
indexes/primary keys defined you will be prompted for those fields when
you run the TransferDatabase method.

When that happens - what I've done is just Escape thru the pop-up prompt
& run a DDL statement (in an Access query) that adds the index/PK
constraints.

Nov 13 '05 #4
Yeah, that's what I'm doing now. I was hoping to run a relink the first
time each user logged in, so that only the tables s/he has at least
SELECT access to would show up. I'll just have to work around it, I
guess. Anyway, thanks again for the helpful advice.

Cheers,

Eric

MGFoster wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SendKyes -> Esc? Not that I know of. Since I consider linking ODBC
tables & views a developing/Administrator event I don't make it user
friendly. It's just a subroutine I run thru the debug window.

Nov 13 '05 #5

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

Similar topics

1
by: Galina | last post by:
Hello I am trying to create a table, which includes a field type LONG. The wizard hasn't allowed me to enter storage settings for this table. It set the initial size is 64K and not available to...
0
by: LesM | last post by:
This is a change of behaviour between Access 2000 SP3 and Access 2002 SP3. I have Progress table that is linked via ODBC into Access using OpenLink Lite for Progress 9.0b. For over a year, using...
3
by: colin.anderson | last post by:
Hi I am trying to refresh table links at startup in an Access 2002 application. The following code is based on a number of articles posted in this group but this does not seem to work: ...
7
by: Patrick Olurotimi Ige | last post by:
I have a simple Stored Procedure with multiple select statements..doing select * from links for example. I created a DataTable and then fill the tables But the first dtTemplate DataTable doesn't...
2
by: mvl_groups_user | last post by:
I am trying to look up data on about 1000 records from a 6 million record view on a DB2 database using msaccess. The 6 million record DB2 view is connected through a linked ODBC table (table A),...
5
by: Randy Harris | last post by:
I've seen several very nice routines on various web sites to fix table links when a file is moved. So far all the ones I've found have used DAO. Anyone know of a sample of such a routine that...
5
by: aaron.m.johnson | last post by:
I have an application which contains an Access database with linked tables that point to another database within the application. The problem I have is that when the user installs the application,...
0
by: rdemyan | last post by:
Is there a way to check the validity of front-end table links on a backend file where all permissions to data have been revoked. To get at the data, the front end uses RWOP queries. What I'm...
1
by: Scott | last post by:
Is it possible to edit/input a ODBC table in MS Access?
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.