'Crea una consulta y la regresa como un recordset
Public Function crearConsulta(baseDeDatos As String, sql As String) As Recordset
Dim bd As Connection, rs As Recordset
Set bd = New Connection
Set rs = New Recordset
'Genera la cadena de conexión
bd.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
baseDeDatos & ";Persist Security Info=False"
'Abre la base de datos
bd.Open
'Se la asigna al recordset
rs.Open sql, bd, adOpenKeyset, adLockOptimistic
If rs.recordCount > 0 Then _
rs.MoveFirst
'Regresa el recordset
Set crearConsulta = rs
End Function