Creating a System DSN for SQL Server from VBA

  • Thread starter Thread starter Lancer
  • Start date Start date
L

Lancer

Hi All...Thanks in advance.

Can anyone point me to the code or attribute list to create a system DSN for
SQL Server from VBA. I want to create the DSN if it doesn't already exist.

Thanks

lance
 
This is the function we use:

Function APP_CreateSQLDataSource(sDSN, sDB, sServer)
On Error GoTo errorCreateSQLDataSource

APP_CreateSQLDataSource = False
Dim sAttrib As String
sAttrib = "Description=DSN Description" &
Chr$(13) & _
"OemToAnsi=No" & Chr$(13) & _
"Server=" & sServer & Chr$(13) & _
"Trusted_Connection=1" & Chr$(13) & _
"Database=" & sDB
' Update Registry.
DBEngine.RegisterDatabase sDSN, "SQL Server", True,
sAttrib
APP_CreateSQLDataSource = True

Exit Function

errorCreateSQLDataSource:
Exit Function
End Function 'APP_CreateSQLDataSource.

You can call the function as follows:
APP_CreateSQLDataSource "DSN Name", "Database
Name", "Server Name"

Probably onOpen of the form.

Thanks
Terri
 
Back
Top