Public Function Extract(fromDate As Date, toDate As Date, sp As String) As Recordset Dim sql As String sql = "select * from sp_aankopen('" & sqlformatDate(fromDate) & "','" & sqlformatDate(toDate) & "')" Debug.Print sql Set rs = New ADODB.Recordset rs.Open sql, conn, adOpenDynamic, adLockOptimistic, -1 Set Extract = rs Set rs = Nothing End FunctionI see now what I did wrong. :)