Personally, I find the manual steps required to link to an ODBC table rather annoying. If you feel the same way, here's how to automate the whole process.
I'd suggest creating a table with three fields,
手动链接ODBC烦死了,如果你有同感,这里将告诉您如何自动连接ODBC。建议创建一个表,表中有三个字段。
LocalTableName -- The name of the ODBC table as it appears in the Database window.
客户端表
ConnectString -- The complete connect string to the ODBC Table. (Can be viewed by
连接表
?CurrentDB.TableDefs("SomeODBCTable").Connect
SourceTable -- The actual name of the ODBC table in the Data source. May be the same as Local Table Name.
服务器表--要求服务器中的表与客户端数据库中的表名一致
Store this information for all ODBC tables in this table (referred to as tblReconnectODBC in code). The benefit is that when this code is run in a new mdb, it re-creates a tabledef for each entry in this table if no ODBC Links are found in the database.
If you want, you can also add RegisterDatabase method to this code when the DSNs are not found in registry. I, unfortunately, haven't had any luck with it since I'm dealing with Oracle.
'****************** Code Start *********************>
' This code was originally written by Dev Ashish.
'本代码的原作者为dew ashish
' It is not to be altered or distributed,
' except as part of an application.
'未经允许不得更改或分发
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
' Code Courtesy of
' Dev Ashish
''您可无偿使用但请在代码中注明原作者:Dev Ashish
Option Compare Database
Option Explicit
Private Type tODBCInfo
strTableName As String
strNewName As String
strConnectString As String
strSourceTable As String
End Type
'Contains all info for tables
Private mastODBCInfo() As tODBCInfo
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Declare Function apiRegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
ByRef phkResult As Long) _
As Long
Private Declare Function apiRegCloseKey Lib "advapi32.dll" _
Alias "RegCloseKey" _
(ByVal hKey As Long) _
As Long
Private Declare Function apiRegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
ByRef lpType As Long, _
lpData As Any, _
ByRef lpcbData As Long) _
As Long
Private Declare Function apiRegQueryInfoKey Lib "advapi32.dll" _
Alias "RegQueryInfoKeyA" _
(ByVal hKey As Long, _
ByVal lpClass As String, _
ByRef lpcbClass As Long, _
ByVal lpReserved As Long, _ 作者: cg1 时间: 2003-4-17 07:22
别告诉我他注册odbc用写注册表的方法阿!????
我会疯掉的,呵呵作者: jhzlzc29 时间: 2003-4-17 16:58