You can programmatically display the standard DataLink property dialog box to let the end user manually build a connection string, that you can later assign to the ConnectionString of an ADO Connection object.
To do so you must add a reference to the Microsoft OLE DB Service Component 1.0 Type Library. By default this library isn’t added to the References dialog box, so you probably have to click on the Browse button inside that dialog, and navigate to the oledb32.dll file, that you should find in the c:Program FilesCommon FilesSystemole db directory. After you have added this reference you can display the standard Data Link dialog using this code:
Dim dataLink As New MSDASC.DataLinksDim connString As StringDim cn As New ADODB.Connection' The following statement makes the property modal respect to the current formdataLink.hWnd = Me.hWnd' Display the dialogOn Error Resume NextconnString = dataLink.PromptNewIf Err = 0 Then ' Create a Connection object on this connection string cn.ConnectionString = connStringElse ' User canceled the operationEnd If
You can also display the same dialog to let the user edit the connection string of an existing Connection object. You do this using the PromptEdit method:
If dataLink.PromptEdit(cn) Then MsgBox cn.ConnectionStringElse MsgBox "Operation canceled"End If