Error entre VBA y SQL Server
Publicado por Jaime (2 intervenciones) el 13/10/2019 19:26:10
Buenas tardes, tengo el siguiente código que establezco conexión con una BD SQL Server para actualizar un campo, lo curioso es que a veces me realiza bien el registro y otras me da error y no logro saber en que fallo, el error me lleva a la linea de la sentencia SQL. paso también la imagen del error

Que puede ser?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'aqui debe guardar toda la informacion en SQL Server
Dim conn As ADODB.Connection
Dim sConnString As String
Dim SQL_String As String
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=SERVIDOR\SQLCONTROLDOC;Initial Catalog=DB" & Sheets("CONFIGURACION").Range("B2").Value & ";Persist Security Info=True;User ID=sa;Password=Cruceni0098.."
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
'Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
If Sheets("PEDIDO").Range("Num_Pedido").Value <> "" Then
SQL_String = "update TBL_Pedidos set Importe=" & Sheets("PEDIDO").Range("Importe_Pedido").Value & _
" WHERE Num_Pedido=" & Sheets("PEDIDO").Range("Num_Pedido").Value & " AND id_Empresa=" & Sheets("CONFIGURACION").Range("B3").Value & ";"
' MsgBox (SQL_String)
conn.Execute ("update TBL_Pedidos set Importe=" & Sheets("PEDIDO").Range("Importe_Pedido").Value & _
" WHERE Num_Pedido=" & Sheets("PEDIDO").Range("Num_Pedido").Value & " AND id_Empresa=" & Sheets("CONFIGURACION").Range("B3").Value & ";")
End If
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
End Sub

Que puede ser?
Valora esta pregunta


0