I want the resulting query to my destiny range without define it in my function, I mean... can I call the destiny range?
Hello, I want to make a query to sql without needing to define a range within the parameters of the function, that is:
Range ("A1") = sqlQuery ("DSN = myODBC;", "SELECT * FROM Table1", TodaLaConsulta)
When executing this line I only load one record from that range and I want the whole table, the code is:
Private Enum TipoConsulta
SoloUnRegistro = 1
TodaLaConsulta = 2
EjecutarQuery = 3
GuardarArray = 4
End Enum
Private Function sqlQuery(ByVal CadenaCnx As String, ByVal Consulta As String, ByVal Tipo As TipoConsulta) As Variant
Dim Cnx As New ADODB.Connection 'Connection
Dim RecSet As New ADODB.Recordset 'Recordset
Cnx.Open CadenaCnx
Select Case Tipo
Case TipoConsulta.SoloUnRegistro
RecSet.Open Consulta, Cnx
sqlQuery = RecSet(0) 'JUST ONE RECORD
Case TipoConsulta.TodaLaConsulta
RecSet.Open Consulta, Cnx
'HERE I WANT THE RESULTING QUERY TO MY DESTINY RANGE WITHOUT DEFINE IT IN MY FUNCTION, I MEAN... CAN I CALL THE DESTINY RANGE??
Range.CopyFromRecordset RecSet
Case TipoConsulta.EjecutarQuery
Cnx.Execute Consulta 'EXECUTE
Case TipoConsulta.GuardarArray
RecSet.Open Consulta, Cnx 'TO ARRAY
sqlQuery = RecSet.GetRows
End Select
RecSet.Close
Cnx.Close
Set RecSet = Nothing
Set Cnx = Nothing
End Function