Hola, que tal
Un gusto en saludarte,funciona de la siguiente manera, primeramente tienes que crear un modulo y pegas el siguiente código:
Código:
Option Explicit
'''#If Win32 Then
'Declaración de la función Api SQLConfigDataSource para 32 bits
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal Frequest As Long, ByVal LpszDriver As String, ByVal lpszAttributes As String) As Long
'''#Else
'''
''''Declaración de la función Api SQLConfigDataSource para 16 bits
'''
'''Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" '''(ByVal hwndParent As Long, ByVal Frequest As Long, '''ByVal LpszDriver As String, ByVal lpszAttributes As String) As Integer
'''
'''#End If
'///Declaración de constantes que utiliza el Api SQLConfigDataSource
'********************************************************************
' Agrega una fuente de datos
Private Const ODBC_ADD_DSN = 4
' Configura o edita una fuente de datos
Private Const ODBC_CONFIG_DSN = 5
' Elimina una fuente de datos
Private Const ODBC_REMOVE_DSN = 6
' Puntero de tipo Null
Private Const vbApiNull As Long = 0&
Public Function CreateDSN(ByVal psDb As String, ByVal psDSNName As String, ByVal psDSNDescription As String, ByVal psDriver As String, ByVal psUser As String, ByVal psPassword As String) As String
On Error GoTo Err_Handler
Dim lsBase As String
Dim lsCadErr As String
' Crea DSN
#If Win32 Then
1 Dim intRet As Long
#Else
2 Dim intRet As Integer
#End If
3 Dim StrDriver As String
4 Dim StrAttributes As String
5 Dim TDriver As Integer
'Define Base
6 lsBase = psDb
'seleccionar tipo de Driver
'sql o Microsoft Access Driver
7 StrDriver = psDriver
' Asignamos los parámetros separador por null
8 StrAttributes = "SERVER=SomeSerVer" & Chr$(0)
9 StrAttributes = StrAttributes & "DESCRIPTION=" & psDSNDescription & Chr$(0)
10 StrAttributes = StrAttributes & "DSN=" & psDSNName & Chr$(0)
11 StrAttributes = StrAttributes & "DATABASE=pubs" & Chr$(0)
12 StrAttributes = StrAttributes & "DBQ=" & psDb & Chr$(0)
13 StrAttributes = StrAttributes & "UID=" & psUser & Chr$(0)
14 StrAttributes = StrAttributes & "PWD=" & psPassword & Chr$(0)
' Para Mostar el cuadro de diálogo, pasarle a SQLConfigDataSource Form1.Hwnd en vez de vbAPINULL
15 intRet = SQLConfigDataSource(vbApiNull, ODBC_ADD_DSN, StrDriver, StrAttributes)
Call Do_Events(1000)
'Si SQLConfigDataSource devuelve un 0 hubo un error.
16 If intRet Then
'Dsn creado correctamente
17 Else
'Error al crear el Dsn
18 lsCadErr = "No se pudo crear la DSN"
19 GoTo Err_Hand
20 End If
Exit Function
Err_Handler:
lsCadErr = Err.Number & "-" & Err.Description
Err_Hand:
CreateDSN = "Linea :" & Erl & " ; " & lsCadErr
End Function Y lo llamas de la siguiente manera : ya sea en un main o en el evento load del mdi :
Código:
lsCadErr = CreateDSN(App.Path & "\Db\SIGMIN.mdb", "oSIGMIN", "oSIGMIN", "Microsoft Access Driver (*.mdb)", "sa", mlPassword)
Espero haberte ayudado
Saludos cordiales,