
13/11/2009, 07:24
|
| | Fecha de Ingreso: septiembre-2009 Ubicación: Venezuela
Mensajes: 92
Antigüedad: 15 años, 7 meses Puntos: 1 | |
Error para exportar datos !!! Buenos dias estimados foristas :
Me encuentro desarrollando una aplicación en visual basic 6. Inicialmente mi manejador de base de datos era access 2003 pero en pro de incrementar las prestaciones de la herramienta por la cantidad de registros, migré a MYSQL.
Ahora bien, con el proceso de migración, algunos códigos no me sirven y por ende he perdido la funcionalidad de algunos módulos.
Ahora bien.. tomando en cuenta esto, necesito ver que problema tengo para que mi software pueda exportar a excel... el código donde hago la consulta de datos es la siguiente :
Sub buscinf()
Dim fecha_a As Date
Dim fecha_b As Date
fecha_a = DTPicker1
fecha_b = DTPicker2
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stsql$
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DRIVER={mysql odbc 3.51 driver};" _
& "SERVER=xxx.xxx.xxx.xxx;" _
& "Database=xxxxxxxxxxxx;" _
& "UID=xxxxxxxxxxxxx;" _
& "password=xxxxxxxxxxxx;" _
& "port=3306;option3 "
cnn.Open
If Check4.Value = 1 Then
Set rst = New ADODB.Recordset
stsql$ = "Select distinct (informe.no_inf),informe.fecha, informe.gte as Gerente, informe.cod_emp, empresas.Empresa from informe, empresas where fecha between ' " & Format(fecha_a, "yyyy/mm/dd") & " 'and '" & Format(fecha_b, "yyyy/mm/dd") & "' and informe.cod_director =" & Text12.Text & " and informe.cod_emp = empresas.cod_emp group by informe.no_inf, informe.fecha, informe.gte, empresas.empresa"
With rst
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open stsql$, cnn, , , adCmdText
End With
rst.MoveFirst
Set DataGrid2.DataSource = rst
DataGrid2.Refresh
Set rst = Nothing
Else
Set rst = New ADODB.Recordset
stsql$ = "Select distinct (informe.no_inf),informe.fecha, informe.gte as Gerente, informe.cod_emp, empresas.Empresa from informe, empresas where informe.cod_director =" & Text12.Text & " and informe.cod_emp = empresas.cod_emp group by informe.no_inf, informe.fecha, informe.gte, empresas.empresa"
With rst
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open stsql$, cnn, , , adCmdText
End With
rst.MoveFirst
Set DataGrid2.DataSource = rst
DataGrid2.Refresh
End If
End Sub
Con esta función obtengo mis resultados... Inicialmente utilizaba adodc pero ahora me da error. LEs adjunto para expotar a excel que no me funciona :
Public Sub Pase_Excel(str_sql As String, strConex As String)
Dim Int_Columnas As Integer
Dim Int_Filas As Integer
Dim rs_main As New ADODB.Recordset
Dim excelApp As Excel.Application
Dim excellibro As Excel.Workbook
Dim excelhoja As Excel.Worksheet
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.ConnectionString = "driver={mysql odbc 3.51 driver};" _
& "SERVER=xxx.xxx.xxx.xxx;" _
& "DATABASE=xxxxxxxxx;" _
& "UID=xxxxxxxxxxxx;" _
& "PASSWORD =xxxxxxxxxxxxx;" _
& "PORT=3306;OPTION=3"
cnn.Open
With rs_main
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
Set .ActiveConnection = Conn
.Open str_sql
End With
Set excelApp = New Excel.Application
Set excellibro = excelApp.Workbooks.Add
Set excelhoja = excellibro.ActiveSheet
Int_Columnas = rs_main.Fields.Count
For I = 1 To Int_Columnas
excelhoja.Cells(1, I) = rs_main.Fields(I - 1).Name
excelhoja.Cells(1, I).Font.Bold = True
excelhoja.Cells(1, I).Font.Size = 12
excelhoja.Cells(1, I).Font.Color = &H81412C
Next
If rs_main.RecordCount > 0 Then
rs_main.MoveFirst
For Int_Filas = 1 To rs_main.RecordCount
For j = 0 To Int_Columnas - 1
If IsNull(rs_main(j).Value) Then
excelhoja.Cells(Int_Filas + 2, j + 1) = ""
Else
excelhoja.Cells(Int_Filas + 2, j + 1) = rs_main(j).Value
End If
Next
rs_main.MoveNext
Next
End If
excelApp.Visible = True
With excelhoja
' -- Autoajustar las cabeceras
.Columns("A:Z").AutoFit
.Columns("E:F").NumberFormat = "###,##0.00"
End With
End Sub
Será que existe otra forma de poder exportar los resultados de mi data grid ????
SALUDOS.
CARLOS. |