You can do something like this!!!
'Use as reference: Microsoft ActiveX Data Objects 2.X Library
'Code:
Public intConnection As ADODB.Connection
Public Sub Open_Conn(Server_Name As String, Data_Base As String, Login As String, Password As String)
Set intConnection = New ADODB.Connection
intConnection.ConnectionString = "driver={SQL Server}" & _
";server=" & Server_Name & _
";uid=" & Login & _
";pwd=" & Password & _
";database=" & Data_Base
intConnection.Open
Activo = True
End Sub
Public Sub Close_Conn()
intConnection.Close
Set intConnection = Nothing
End Sub
Private Function Get_Value(Field As String, Table As String) As String
Dim rstValue As ADODB.Recordset
Dim strQry As String
strQry = "SELECT " & Field & " FROM " & Table
Set rstValue = New ADODB.Recordset
rstValue.Open strQry, intConnection, adOpenStatic, adLockReadOnly, adCmdText
If rstValue.EOF Then
Get_Value = ""
Else
Get_Value = strQry(0)
End If
rstValue.Close
Set rstValue = Nothing
End Function