hespenheide
New member
- Local time
- Yesterday, 21:19
- Joined
- Apr 22, 2010
- Messages
- 1
Hi
I have an autoexec macro in Access 2007 designed to create linked tables to a DB2 database. If I use either a system DSN or user DSN file (via the linked table manager), the linking works fine. However, if I attempt the linking in VBA, the app pops up a "Connect to DB2 Database" window where it is asking for a "Database alias" before it will allow me to connect.
Here is a snippet of the code. The stars represent real values:
Dim db As Database
Set db = CurrentDb
Dim tdf As TableDef
'Remove all ODBC tables from the table definitions
For a = CurrentDb.TableDefs.Count - 1 To 0 Step -1
If Left(CurrentDb.TableDefs(a).Connect, 4) = "ODBC" Then
db.TableDefs.Delete db.TableDefs(a).Name
End If
Next a
Application.RefreshDatabaseWindow
Set tdf = db.CreateTableDef("ACCESS_TABLE")
tdf.Connect = "ODBC;Driver={IBM DB2 ODBC DRIVER};AUTHENTICATION=SERVER;PORT=60001;HOSTNAME=FLOAT.****.COM;PROTOCOL=TCPIP;DATABASE=******;"
tdf.SourceTableName = "DB2_TABLE"
db.TableDefs.Append tdf
The "Connect to DB2 Database" window pops up when I try to append the new table.
Any help will be greatly appreciated.
Thank you
I have an autoexec macro in Access 2007 designed to create linked tables to a DB2 database. If I use either a system DSN or user DSN file (via the linked table manager), the linking works fine. However, if I attempt the linking in VBA, the app pops up a "Connect to DB2 Database" window where it is asking for a "Database alias" before it will allow me to connect.
Here is a snippet of the code. The stars represent real values:
Dim db As Database
Set db = CurrentDb
Dim tdf As TableDef
'Remove all ODBC tables from the table definitions
For a = CurrentDb.TableDefs.Count - 1 To 0 Step -1
If Left(CurrentDb.TableDefs(a).Connect, 4) = "ODBC" Then
db.TableDefs.Delete db.TableDefs(a).Name
End If
Next a
Application.RefreshDatabaseWindow
Set tdf = db.CreateTableDef("ACCESS_TABLE")
tdf.Connect = "ODBC;Driver={IBM DB2 ODBC DRIVER};AUTHENTICATION=SERVER;PORT=60001;HOSTNAME=FLOAT.****.COM;PROTOCOL=TCPIP;DATABASE=******;"
tdf.SourceTableName = "DB2_TABLE"
db.TableDefs.Append tdf
The "Connect to DB2 Database" window pops up when I try to append the new table.
Any help will be greatly appreciated.
Thank you