|
生平我最恨洋文,以下是我乱译一气,请英语好的网友帮忙完善一下:
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
'*** Registry stuff
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_DYN_DATA = &H80000006
Private Const STANDARD_RIGHTS_READ = &H20000
Private Const KEY_QUERY_VALUE = &H1&
Private Const KEY_ENUMERATE_SUB_KEYS = &H8&
Private Const KEY_NOTIFY = &H10&
Private Const Synchronize = &H100000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY) And _
(Not Synchronize))
Private Const MAXLEN = 256
Private Const ERROR_SUCCESS = &H0&
Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_RESOURCE_LIST = 8
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, _
|
|