Public Function GetData() As ADODB.Recordset Dim rs As ADODB.Recordset Dim conn As ADODB.Connection Dim strsql As String strsql = "select FirstName from dbo.Employees" Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.ConnectionString = "Provider=sqlOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=127.0.0.1" conn.Open With rs .CursorLocation = adUseClient .CursorType = adOpenForwardOnly .LockType = adLockReadOnly .ActiveConnection = conn .Open strsql End With Set GetData = rs Set conn = Nothing Set rs = Nothing End Function