Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Error en sentencia SQL con VBA

publicado

Hola a todos, de nuevo un problema.

Llevo tiempo mirando y leyendo y no acabo de ver donde está el error.

Tengo un formulario donde lleno los Combobox y Textbox con una consulta SQL y la fuente es un Access. Hasta aquí bien, he conseguido que lo haga bien.

Pero le he puesto un botón para actualizar el registro Access con los datos del formulario. He probado solo actualizando un registro y funciona pero ahora que ya he puesto todos los campos a actualizar y me da un error en sintaxis en la instrucción UPDATE. Hay datos que son números en el Access y los formate a moneda en los Textbox, y por eso he utilizado unas variables por si eso daba problemas, lo mismo no hacía falta pero como fallaba he probado. Aún así persiste el error. Por mucho que lo intento no logro ver el fallo y que funcione.

Os agradezco si podéis echarme una mano. Copio el código del botón:

Private Sub CommandButton2_Click()
'boton Editar, actualizamos el registro y salimos del formulario
eImporte = TextBox4.Value: ePorcentaje = TextBox5.Value / 100: ePrevisto = TextBox6.Value: eContable = TextBox7.Value: eCurso = TextBox8.Value
id1 = UserForm3.ListBox2.List(it2, 0) 'cogemos el ID del registro del Listbox Checklist seleccionado
Conexión
 Sql = "UPDATE Tb_Checklist SET OT='" & ComboBox1 & "'" & ", AGRUPACION='" & ComboBox3 & "'" & ", GRUPO='" & ComboBox4 & _
 "'" & ", Periodo_Checklist='" & ComboBox2 & "'" & ", Proveedor='" & TextBox1 & "'" & ", Referencia='" & TextBox2 & "'" & _
 ", Usuario='" & TextBox3 & "'" & ", Importe=" & eImporte & ", Porcentaje=" & ePorcentaje & ", Previsto=" & ePrevisto & _
 ", Contable=" & eContable & ", En_Curso=" & eCurso & " WHERE ID =" & id1
Rst.Open Sql, Conn, 3, 3, 1
'
Conn.Close
Set Conn = Nothing
Unload Me
End Sub

Aquí veis el formulario que carga los datos. El error me salta aunque no modifique ningún dato del formulario.

image.thumb.png.8feff09a323d6c22e84f067af0f3d4a7.png

Y aquí el error.

image.png.8688ed76781cbce2b41406d3589af22f.png

Gracias por adelantado.

Moisés.

Featured Replies

publicado
  • Autor

Hola a todos. Ya he conseguido que funcione.

He ido probando la instrucción UPDATE poco a poco hasta completarla sin que falle la sintaxis y al final ha quedado así.

Private Sub CommandButton2_Click()
'boton Editar, actualizamos el registro y salimos del formulario
id_1 = UserForm3.ListBox2.List(it2, 0) 'cogemos el ID del registro del Listbox Checklist seleccionado
'
Conexión
 Sql = "UPDATE Tb_Checklist SET OT='" & ComboBox1 & "', AGRUPACION='" & ComboBox3 & "', GRUPO='" & ComboBox4 & _
 "', Periodo_Checklist='" & ComboBox2 & "', Proveedor='" & TextBox1 & "', Referencia='" & TextBox2 & _
 "', Usuario='" & TextBox3 & "', Importe='" & TextBox4 & "', Porcentaje='" & TextBox5.Value / 100 & _
 "', Previsto='" & TextBox6 & "', Contable='" & TextBox7 & "', En_Curso='" & TextBox8 & _
 "' WHERE ID =" & id_1
Rst.Open Sql, Conn, 3, 3, 1
'
Conn.Close
Set Conn = Nothing
Unload Me
End Sub

Gracias de todos modos.

Moisés.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.