Let the user build a connection string

Let the user build a connection string

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


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist