Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass values to ADO connection-need syntax 1

Status
Not open for further replies.

gcole

Programmer
Joined
Aug 2, 2000
Messages
390
Location
US
I am using the following function to open a SQL connection:
Public Function OpenADODb(sProvider As String, sServer As String, sDatabase As String, sUserId As String, sPassword As String) As ADODB.Connection

Const FORM_NAME = "cADO"
Dim oCn As New ADODB.Connection
Dim sCnStr As String

sCnStr = "Provider=SQLOLEDB + ';Server=actualserver;" & _
"Database=actualdb;User Id=xx;Password=xxxx;"

oCn.Open sCnStr

Set OpenADODb = oCn


EXIT_PROC:
Exit Function
End Function

What is the syntax for using the values I am passing instead of hardcoding them?
Thanks for your help!
 
Public Function OpenADODb(sProvider As String, sServer As String, sDatabase As String, sUserId As String, sPassword As String) As ADODB.Connection
Dim oCn As New ADODB.Connection
Dim sCnStr As String

sCnStr = "Provider=" & sProvider & _
" + ';Server=" & sServer & ";" & _
"Database=" & sDatabase & ";" & _
"User Id=" & sUserID &";" & _
"Password=" & sPassword & ";"

oCn.Open sCnStr

Set OpenADODb = oCn
END FUNCTION
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top