duda de excel con oracle
hola, mi duda es que tengo una consulta desde excel y al mostrarme el resultado me hace un loop donde me muestra todos los resultados pisando el anterior, quiero que muestre el resultado en una lista de excel hacia abajo, pero no lo consigo, alguien me puede ayudar??
coloco el codigo:
Private Sub CommandButton1_Click()
Dim bd As New Connection
Dim rs As Recordset
Dim sql As String
Dim fila
'bd.Open "MAx411" '<-- La ODBC se debe llamar como le pongas aquÃ
bd.Open "DRIVER={ORACLE ODBC DRIVER};SERVER=MAXIMO;DATA SOURCE = MAx411;UID=practica;PWD=practica;"
fila = 2
Location = Trim(Hoja1.Cells(fila, "a"))
Description = Trim(Hoja1.Cells(fila, "b"))
Hoja1.Cells(fila, "c") = ""
Hoja1.Cells(fila, "d") = ""
While Location <> ""
' Consulta SQL
sql = "Select location from LOCATIONS "
sql = sql & "where "
sql = sql & "LOCATIONS.description like '%" & santiago & "%' "
'MsgBox sql
Set rs = bd.Execute(sql) '<-- Ejecutas la consulta SQL
Do While Not rs.EOF 'Then
Hoja1.Cells(fila, "c") = Trim(rs.Fields("location").Value) '<-- Obtienes VALORES
'Hoja1.Cells(fila, "d") = Trim(rs.Fields("description").Value)
rs.MoveNext
Loop
'End If
fila = fila + 1
Location = Trim(Hoja1.Cells(fila, "a"))
' Description = Trim(Hoja1.Cells(fila, "b"))
Hoja1.Cells(fila, "c") = ""
Hoja1.Cells(fila, "d") = ""
Wend
bd.Close '<-- MUY IMPORTANTE... CERRAR LA BASE DE DATOS!!!
End Sub
coloco el codigo:
Private Sub CommandButton1_Click()
Dim bd As New Connection
Dim rs As Recordset
Dim sql As String
Dim fila
'bd.Open "MAx411" '<-- La ODBC se debe llamar como le pongas aquÃ
bd.Open "DRIVER={ORACLE ODBC DRIVER};SERVER=MAXIMO;DATA SOURCE = MAx411;UID=practica;PWD=practica;"
fila = 2
Location = Trim(Hoja1.Cells(fila, "a"))
Description = Trim(Hoja1.Cells(fila, "b"))
Hoja1.Cells(fila, "c") = ""
Hoja1.Cells(fila, "d") = ""
While Location <> ""
' Consulta SQL
sql = "Select location from LOCATIONS "
sql = sql & "where "
sql = sql & "LOCATIONS.description like '%" & santiago & "%' "
'MsgBox sql
Set rs = bd.Execute(sql) '<-- Ejecutas la consulta SQL
Do While Not rs.EOF 'Then
Hoja1.Cells(fila, "c") = Trim(rs.Fields("location").Value) '<-- Obtienes VALORES
'Hoja1.Cells(fila, "d") = Trim(rs.Fields("description").Value)
rs.MoveNext
Loop
'End If
fila = fila + 1
Location = Trim(Hoja1.Cells(fila, "a"))
' Description = Trim(Hoja1.Cells(fila, "b"))
Hoja1.Cells(fila, "c") = ""
Hoja1.Cells(fila, "d") = ""
Wend
bd.Close '<-- MUY IMPORTANTE... CERRAR LA BASE DE DATOS!!!
End Sub
