I can get a new new DSN to set up on the fly and have it entered into the
registry. I can get a DSN to write into the registry but I can't ever get
it to show as a system DSN in the "control panel|ODBC Data Source
Administrator" Any Ideas how I can go about this? This is very important.
Thank you very much. Here are some snippits:
DataSourceName = "MyDsn"
Engines = "Engines"
Jet = "Jet"
DBQPath = DataBaseLocation
Driver = "C:\Windows\system\odbcjt32.dll"
UID = ""
FIL = "MS Access;"
DriverId = &H19
SafeTransaction = &H0
ImplicitCommitSync = ""
MaxBufferSize = &H800
PageTimeOut = &H5
Threads = &H3
UserCommitSync = "yes"
Password = "password"
'Specify the DSN parameters.
'Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
DataSourceName, hKeyHandle)
'DBQ
lResult = RegSetValueEx(hKeyHandle, "DBQ", 0&, REG_SZ, _
ByVal DBQPath, Len(DBQPath))
'Driver
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal Driver, Len(Driver))
lResult = RegSetValueExA(hKeyHandle, "DriverId", 0, REG_DWORD, DriverId,
4) 'write the value
'FIL
lResult = RegSetValueEx(hKeyHandle, "FIL", 0&, REG_SZ, _
ByVal FIL, Len(FIL))
lResult = RegSetValueExA(hKeyHandle, "SafeTransaction", 0, REG_DWORD,
SafeTransaction, 4) 'write the value
'Password
lResult = RegSetValueEx(hKeyHandle, "PWD", 0&, REG_SZ, _
ByVal Password, Len(Password))
'UID
lResult = RegSetValueEx(hKeyHandle, "UID", 0&, REG_SZ, _
ByVal UID, Len(UID))
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" &
DataSourceName & "\" & _
Engines, hKeyHandle)
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" &
DataSourceName & "\" & Engines & "\" & _
Jet, hKeyHandle)
'ImplicitCommitsync
lResult = RegSetValueEx(hKeyHandle, "ImplicitCommitSync", 0&, REG_SZ, _
ByVal ImplicitCommitSync, Len(ImplicitCommitSync))
'MaxBufferSize
lResult = RegSetValueExA(hKeyHandle, "MaxBufferSize", 0, REG_DWORD,
MaxBufferSize, 4) 'write the value
'PageTimeOut
lResult = RegSetValueExA(hKeyHandle, "PageTimeOut", 0, REG_DWORD,
PageTimeOut, 4) 'write the value
'Threads
lResult = RegSetValueExA(hKeyHandle, "Threads", 0, REG_DWORD, Threads, 4)
'write the value
'UserCommitSync
lResult = RegSetValueEx(hKeyHandle, "UserCommitSync", 0&, REG_SZ, _
ByVal UserCommitSync, Len(UserCommitSync))
'Close the new DSN key.
lResult = RegCloseKey(hKeyHandle)
'Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
'Specify the new value.
'Close the key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
ByVal DriverName, Len(DriverName))
lResult = RegCloseKey(hKeyHandle)
MsgBox "The database located at """ & DataBaseLocation & """ was found
and a DSN was " _
& "set up", vbInformation + vbDefaultButton1 + vbOKOnly, "Success"