Puoi memorizzare la stringa di connessione nel registry o in un file e quindi lasciare che sia l'utente finale a crearsela con l'apposita finestra.
Metti questo codice in una classe:
codice:
Option Explicit
Public Function EditCnn(ByVal phWnd As Long, ByRef pCnnStringToModify As String) As Boolean
Dim myCnnstring As String
Dim myCnn As ADODB.Connection
Dim AdoWizard As DataLinks
Set myCnn = New ADODB.Connection
myCnn.ConnectionString = pCnnStringToModify
Set AdoWizard = New DataLinks
AdoWizard.HWnd = phWnd
'Edit cnnString
If AdoWizard.PromptEdit(myCnn) Then
'Ok edit
EditCnn = True
pCnnStringToModify = myCnn.ConnectionString
Set myCnn = Nothing
Set AdoWizard = Nothing
Exit Function
Else
'Cancel
EditCnn = False
Set myCnn = Nothing
Set AdoWizard = Nothing
Exit Function
End If
End Function
Public Function NewCnn(ByVal phWnd As Long, ByRef pCnnStringResult As String) As Boolean
Dim myCnnstring As String
Dim myCnn As ADODB.Connection
Dim AdoWizard As DataLinks
Set AdoWizard = New DataLinks
AdoWizard.HWnd = phWnd
'new cnn string
Set myCnn = AdoWizard.PromptNew
If Not myCnn Is Nothing Then
'Ok new
NewCnn = True
pCnnStringResult = myCnn.ConnectionString
Set myCnn = Nothing
Set AdoWizard = Nothing
Exit Function
Else
'Cancel
NewCnn = False
Set myCnn = Nothing
Set AdoWizard = Nothing
Exit Function
End If
End Function
Quindi includi tra i riferimenti:
"Microsoft OLE DB Service Component x.x Type Library" (OLEDB32.dll).
In alternativa puoi assegnare ogni parametro ad una variabile stringa (che leggi sempre dal registry o da un file di cfg) che poi concateni.
Un titolo migliore?