View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E[_2_] AA2e72E[_2_] is offline
external usenet poster
 
Posts: 93
Default Try again: VBA to automatically install ODBC data source

Yes you can create DSN pogramatically. Research the two functions in the following declarations

Declare Function SQLCreateDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long,ByVal lpszDS As String) As Lon
Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" ( ByVal hwndParent as Long, ByVal fRequest as Long, ByVal lpszDriver as String, ByVal lpszAttributes as String ) as Lon

The available DSNs are listed at these nodes in the registry

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\odbc.ini ' System DSN
HKEY_CURRENT_USER\SOFTWARE\ODBC\odbc.ini ' User DSN

So, in order to add a DSN programatically, you need to

1. ensure that it does not exist already (by reading the registry
2. that the name you are choosing is unique (on all target PCs so that your application has a single unique name to refer to

Neither of these are straightforward

Why not use DSN-less connections?