by Alexandros Zountas (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 14th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Prompt user for connection and build the connection string at runtime, with the known interface that VB uses. Works with OLEDB and ODBC.
'1. Microsoft OLE DB Service Component 1.0
'2. Microsoft ADO 2.5
Public Function GetConnectionString(Optional strOLE As String = "OLEDB") As String
On Error GoTo ErrHandler
Dim cn As ADODB.Connection
Dim objDataLink As MSDASC.DataLinks
Set cn = New ADODB.Connection
Set objDataLink = New MSDASC.DataLinks
Select Case strOLE
Case "OLEDB"
cn = objDataLink.PromptNew
GetConnectionString = cn.ConnectionString
Case "ODBC"
cn.ConnectionString = ""
cn.Properties("Prompt") = adPromptAlways
cn.Open
GetConnectionString = cn.ConnectionString
cn.Close
End Select
Exit Function
ErrHandler:
' skip known error conditions; otherwise, report error
' (e.g. skip ODBC builder 'action cancelled' error)
If Err.Number = 91 Or Err.Number = -2147217842 Then
Exit Function
Else
MsgBox "Error: " & Err.Description
End If
End Function
No comments have been posted about Prompt user for connection and build the connection string at runtime, with the known interface tha. Why not be the first to post a comment about Prompt user for connection and build the connection string at runtime, with the known interface tha.