Macro excel-sql

Buenos días:
He diseñado una interfaz en excel con el editor de visual que me modifica una base de datos en SQL. Cuando abro el libro y luego cargo la interfaz no tendo problema; pero cuando utilizo el evento open del libro (workbook open) para cargar la interfaz y ejecuto cualquier comando ya sea para insertar o modificar registros siempre me produce el mismo error : Se ha producido el error '1004' en tiempo de ejecución:error definido por la aplicación del objeto... El depurador de visual siempre se detiene en la instrucción:
.Refresh BackgroundQuery:=True
He intentado utilizando varias instrucciones en el evento open para cargar el formulario: load, show o ambas pero siempre obtengo el mismo error. La única forma de que no me genere ningún error es abrir primero el libro y luego cargar la interfaz.
Si me pudieras colaborar quedaría muy agradecido. De antemano muchas gracias por tu tiempo e interés.
Saludos,
John

1 respuesta

Respuesta
1
. Refresh All
[email protected]
Primero que todo gracias por tu pronta respuesta y tu interés. Te cuento que refreshall ya lo había intentado y tampoco funciono. Un dato adicional. Si la corro en windows vista me funciona perfecto, pero no si es XP o 2003 server.
Nuevamente gracias
¿Te aseguras de cerrar las conexiones?
[email protected]
Utilizo el comando "End" para descargar la interfaz, y posteriormente cierro el archivo de excel, supongo que eso cierra las conexiones.
Gracias
¿Puedes poner parte del código?
[email protected]
Private Sub CommandButton2_Click()
Dim Z As String, W As Integer
Application.ScreenUpdating = False
If TCConsecutivo <> "" Then
x = MultiPage1.Value
Pagina = Right(MultiPage1.Pages(x).Name, 2)
For Each ctr In Me.Controls
If TypeName(ctr) = "TextBox" Then
Z = ctr.Name
If Z <> "TCConsecutivo" Then
If (Left(ctr.Name, 5) = "TD" & Pagina & "R") Then
nc1.Add ctr
End If
End If
End If
Next ctr
For Each ctr In nc1
Z = ctr.Name
If ctr.Text = "" Then
MsgBox "Falta informacion en campo que indica el Cursor " & ctr.ControlTipText & ""
ctr.SetFocus
Exit Sub
End If
Next ctr
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=servidor1;UID=sa;PWD=admin;APP=Microsoft Office XP;WSID=SERVIDOR1;DATABASE=fursoat" _
, Destination:=Range("DX1"))
.CommandText = Array( _
"SELECT furips1.ipsdatvic " & Chr(13) & "" & Chr(10) & _
"FROM fursoat.dbo.furips1 furips1" & Chr(13) & "" & Chr(10) & _
"WHERE (furips1.ipsconsec='" & TCConsecutivo & "')" _
)
.Name = "Consulta desde CContable"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Worksheets(1).QueryTables(1).Refresh
W = Range("DX2")
b_act = 0
If W = 1 Then
Range("DX2") = ""
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=servidor1;UID=sa;PWD=admin;APP=Microsoft Office XP;WSID=SISTEMAS2;DATABASE=fursoat;Network=DBNMPNTW" _
, Destination:=Range("A1"))
.CommandText = Array( _
"DELETE fursoat.dbo.furipsvic WHERE (furipsvic.ipsconsec='" & TCConsecutivo & "')" _
)
.Name = "Consulta desde CContable"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
EL DEPURADOR SE DETIENE EN LA LINEA SGTE
.Refresh BackgroundQuery:=True
End With
b_act = 1
End If
Pareciera que todo está bien. Me dices que has intentado refrescar de varias formas y no ha sido posible, voy a ver que otras formas encuentro. A mi me funciona con ThisWorkbook. RefreshAll
[email protected]
De verdad agradezco el gran interés demostrado y tu tiempo y colaboracion; te cuento que lo intento con la instrucción que me diste pero igual reporta el mismo error. De la única manera que no molesta es cuando abro primero el archivo y luego cargo la interfaz; y supongo que así lo voy a dejar.
Nuevamente muchas gracias por tu colaboración,

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas