Valores nulos en fechas

Nuevamente acudo a usted con otro problema, necesito insertar valores nulos a la base de datos, más exactamente una fecha, en el código que usted me ayudo a construir la fecha de retiro de un empleado en ocasiones debe estar nula, ya que el empleado esta activo, solo se le coloca información cuando el empleado se ha retirado.
El código que utilice es el siguiente:
Private Sub cmdguardar_Click()
Dim QryInsert As String, QryUpdate As String
If txtCedula.Text = "" Then MsgBox "El Campo Cedula no Puede estar Vacio", vbInformation, "Aviso": txtCedula.SetFocus: Exit Sub
If txtLugar.Text = "" Then MsgBox "El Campo Lugar de Expedicion no Puede estar Vacio", vbInformation, "Aviso": txtLugar.SetFocus: Exit Sub
If txtNombres.Text = "" Then MsgBox "El Campo Nombres no Puede estar Vacio", vbInformation, "Aviso": txtNombres.SetFocus: Exit Sub
If txtApellidos.Text = "" Then MsgBox "El Campo Apellidos no Puede estar Vacio", vbInformation, "Aviso": txtApellidos.SetFocus: Exit Sub
If txtFecha.Text = "" Then MsgBox "El Campo Fecha de Nacimiento no Puede estar Vacio", vbInformation, "Aviso": txtFecha.SetFocus: Exit Sub
If Modificar = False Then
'Base.Execute
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "'" & txtRetiro.Text & "'," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Else
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = '" & txtRetiro.Text & "'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
Set RecSql = New ADODB.Recordset
'MsgBox "" & QryUpdate
RecSql.Open QryUpdate, CnXn, adOpenKeyset, adLockOptimistic
End If
Habilitarcajas True
Habilitarbotones True, False
End Sub
Por favor necesito su orientación nuevamente, ya prove la opción con IIF NULL Y NO PUDE ENCONTRAR NADA.

1 Respuesta

Respuesta
1
Podrías hacer lo siguiente, primero debes tener dos insert con el mismo código y todo, pero al momento de insertar los datos en la BD si no quieres insertar nada en vez que el textbox sea " " (vacío) le dices.
if txtretiro.text  = "" then
en la insercion del dato le pones "NULL"
else
la query normal como la construimos
end if
Prueba eso y me cuentas.
Buenas noches, la verdad no le podido entender lo que me dice, trate de construir el código como me indico y no resulta, el compilador me dice que se esperaba: numero de linea o etiqueta o instrucción o fin de la instrucción.
Asi construi el codigo
QryInsert = "INSERT INTO Empleados (Fecha_Retiro) "VALUES"
          If txtRetiro.Text = "" Then
          "Null"
          Else
          txtRetiro.Text
          End If
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Espero por favor me ayude y gracias por todo el tiempo que ha dedicado a resolver mis dudas.
If txtRetiro.Text = "" Then
QryInsert = "INSERT INTO Empleados (Fecha_Retiro) "VALUES"( 'Null')
          Else
QryInsert = "INSERT INTO Empleados (Fecha_Retiro) "VALUES"( txtretiro.text)
End If
Set RecSql = New ADODB.Recordset
RecSql. Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Así era la idea que había dado en un principio acomoda el código para que no te de error, la idea era que si el txtretiro era = vacío que insertara un valor null de lo contrario que fuera el valor que tiene el txtretiro.
Buenas noches experto, la verdad no le entiendo, como puedo acomodar el código, no lo he podido hacer, siempre me resulta un error de sintaxis.
Por favor oriénteme un poco más.
Buenas noches, se me ocurrió el siguiente código
QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & IIf(IsDate(txtRetiro), "#" & txtRetiro & "#", "Null") & _
          "'" & txtRetiro.Text & "'," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Pero resulta el siguiente error: error de sintaxis (falta operador) en la expresión de consulta "Null",'Masculino')' y me lleva a la siguiente linea:
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
La verdad no entiendo, que me sugiere al respecto, gracias.
Amigo mio perdón por la demora,
copia este código en tu botón de guardar.
Private Sub cmdguardar_Click()
Dim QryInsert As String, QryUpdate As String
If txtCedula.Text = "" Then MsgBox "El Campo Cedula no Puede estar Vacio", vbInformation, "Aviso": txtCedula.SetFocus: Exit Sub
If txtLugar.Text = "" Then MsgBox "El Campo Lugar de Expedicion no Puede estar Vacio", vbInformation, "Aviso": txtLugar.SetFocus: Exit Sub
If txtNombres.Text = "" Then MsgBox "El Campo Nombres no Puede estar Vacio", vbInformation, "Aviso": txtNombres.SetFocus: Exit Sub
If txtApellidos.Text = "" Then MsgBox "El Campo Apellidos no Puede estar Vacio", vbInformation, "Aviso": txtApellidos.SetFocus: Exit Sub
If txtFecha.Text = "" Then MsgBox "El Campo Fecha de Nacimiento no Puede estar Vacio", vbInformation, "Aviso": txtFecha.SetFocus: Exit Sub
If Modificar = False Then
'Base.Execute
 If Not txtRetiro.Text = "" Then
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "'" & txtRetiro.Text & "'," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
 Else
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "'01-01-3000'," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
 End If
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Else
   If Not txtRetiro.Text = "" Then
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = '" & txtRetiro.Text & "'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
   Else
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = '01-01-3000'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
   End If
Set RecSql = New ADODB.Recordset
'MsgBox "" & QryUpdate
RecSql.Open QryUpdate, CnXn, adOpenKeyset, adLockOptimistic
End If
Habilitarcajas True
Habilitarbotones True, False
Lo que hice fue que cuando hagas el clic en el botón vea si el textbox esta vacío o no, dependiendo de eso es lo que hace, toma una query u otra, en el fondo si la fecha de retiro no existe le puse como dato fijo que guarde 01-01-3000 esa fecha lógicamente no es una fecha de retiro. Si estas de acuerdo con eso lo copias o si no házmelo saber y buscamos otra solución.
Si prefieres ocupa este otro código, que este si guarda el Null
Dim QryInsert As String, QryUpdate As String
If txtCedula.Text = "" Then MsgBox "El Campo Cedula no Puede estar Vacio", vbInformation, "Aviso": txtCedula.SetFocus: Exit Sub
If txtLugar.Text = "" Then MsgBox "El Campo Lugar de Expedicion no Puede estar Vacio", vbInformation, "Aviso": txtLugar.SetFocus: Exit Sub
If txtNombres.Text = "" Then MsgBox "El Campo Nombres no Puede estar Vacio", vbInformation, "Aviso": txtNombres.SetFocus: Exit Sub
If txtApellidos.Text = "" Then MsgBox "El Campo Apellidos no Puede estar Vacio", vbInformation, "Aviso": txtApellidos.SetFocus: Exit Sub
If txtFecha.Text = "" Then MsgBox "El Campo Fecha de Nacimiento no Puede estar Vacio", vbInformation, "Aviso": txtFecha.SetFocus: Exit Sub
If Modificar = False Then
'Base.Execute
 If Not txtRetiro.Text = "" Then
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "'" & txtRetiro.Text & "'," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
 Else
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "Null," & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
 End If
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Else
   If Not txtRetiro.Text = "" Then
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = '" & txtRetiro.Text & "'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
   Else
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = Null," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
   End If
Set RecSql = New ADODB.Recordset
'MsgBox "" & QryUpdate
RecSql.Open QryUpdate, CnXn, adOpenKeyset, adLockOptimistic
End If
Habilitarcajas True
Habilitarbotones True, False
Saludos, te recomiendo este código ya que es el estabas solicitando.
Buenas Noches, utilice su código recomendado y resulto el siguiente error
Error en tiempo de ejecución: Desbordamiento, y me muestra la siguiente linea
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Que me recomienda ahora, gracias...
Eso es cuando insertas un nuevo código pero a mi no me mande el error de overflow, de ser así cambia el tipo de variable, las variables que sean Integer cambialas por Long, por ejemplo:
si tienes esto, Dim dato as Integer,
lo dejas asi, Dim dato as Long
Buenas Noches experto, la verdad no logro dar con el error, no he cambiado el código como usted comenta, lo que si modifique fueron las variables declaradas como me sugirió y resulta el siguiente error: error 13 en tiempo de ejecución no coinciden los tipos.
Le adjunto el código completo que estoy utilizando para que se oriente mejor y me pueda dar una luz de solución a este problema.
'Desde aqui en adelante copia
Dim CnXn As Connection
Dim RecSql As Recordset
Private Sub Cmd_Click()
Habilitarcajas False
Limpiar
Modificar = False
Habilitarbotones False, True
End Sub
Private Sub cmdCancelar_Click()
Habilitarbotones True, False
Habilitarcajas True
Limpiar
End Sub
Private Sub cmdmodificar_Click()
Habilitarcajas False
Modificar = True
Habilitarbotones False, True
End Sub
Private Sub cmdNuevo_Click()
Habilitarcajas False
Limpiar
Modificar = False
Habilitarbotones False, True
End Sub
Private Sub cmdSalir_Click()
Unload Me
End Sub
Private Sub cmdguardar_Click()
Dim QryInsert As Long, QryUpdate As Long
If txtCedula.Text = "" Then MsgBox "El Campo Cedula no Puede estar Vacio", vbInformation, "Aviso": txtCedula.SetFocus: Exit Sub
If txtLugar.Text = "" Then MsgBox "El Campo Lugar de Expedicion no Puede estar Vacio", vbInformation, "Aviso": txtLugar.SetFocus: Exit Sub
If txtNombres.Text = "" Then MsgBox "El Campo Nombres no Puede estar Vacio", vbInformation, "Aviso": txtNombres.SetFocus: Exit Sub
If txtApellidos.Text = "" Then MsgBox "El Campo Apellidos no Puede estar Vacio", vbInformation, "Aviso": txtApellidos.SetFocus: Exit Sub
If txtFecha.Text = "" Then MsgBox "El Campo Fecha de Nacimiento no Puede estar Vacio", vbInformation, "Aviso": txtFecha.SetFocus: Exit Sub
If Modificar = False Then
'Base.Execute
 QryInsert = "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'" & _
          "'" & txtLugar.Text & "','" & _
          "'" & txtNombres.Text & "','" & _
          "'" & txtApellidos.Text & "','" & _
          "'" & txtFecha.Text & "','" & _
          "'" & txtIngreso.Text & "','" & _
          "'" & txtRetiro.Text & "','" & _
          "'" & sexo.Text & "')" 'doy por hecho que este es un combobox
Set RecSql = New ADODB.Recordset
RecSql.Open QryInsert, CnXn, adOpenKeyset, adLockOptimistic
Else
   QryUpdate = "UPDATE Empleados Set Cedula = " & txtCedula.Text & "," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = '" & txtRetiro.Text & "'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & ""
Set RecSql = New ADODB.Recordset
'MsgBox "" & QryUpdate
RecSql.Open QryUpdate, CnXn, adOpenKeyset, adLockOptimistic
End If
Habilitarcajas True
Habilitarbotones True, False
End Sub
Sub Limpiar()
txtCedula.Text = ""
txtLugar.Text = ""
txtNombres.Text = ""
txtApellidos.Text = ""
txtFecha.Text = ""
txtIngreso.Text = ""
txtRetiro.Text = ""
lbltrabajo.Caption = ""
lbledad.Caption = ""
txtCedula.SetFocus
End Sub
Public Sub Habilitarcajas(estado As Boolean)
txtCedula.Locked = estado
txtLugar.Locked = estado
txtNombres.Locked = estado
txtApellidos.Locked = estado
txtFecha.Locked = estado
txtIngreso.Locked = estado
txtRetiro.Locked = estado
End Sub
Private Sub Form_Load()
Set CnXn = New ADODB.Connection
CnXn.Provider = "Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\LABORAL.mdb;Jet OLEDB:Database Password=false;"
CnXn.Open
Habilitarcajas True
Habilitarbotones True, False
sexo.AddItem "Masculino"
sexo.AddItem "Femenino"
sexo.ListIndex = 0
End Sub
Public Sub Habilitarbotones(estado1 As Boolean, estado2 As BookmarkEnum)
cmdNuevo.Enabled = estado1
cmdModificar.Enabled = estado1
cmdGuardar.Enabled = estado2
cmdCancelar.Enabled = estado2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Empleados
Set EmpleadosForm.grillaEmpleados.DataSource = RSEmpleados
EmpleadosForm.CerrarGrilla
End Sub
Private Sub sexo_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Espero sus comentarios y de ante mano gracias...
Amigo mio que ha salido difícil esto ja ja pero ahora creo que si te funcionara hice algunas modificaciones copia tal cual el código fuente, y el que tienes en tu proyecto cópialo en un *.txt para que lo analices y sepas donde están las modificaciones suerte amigo mio...
'Desde aqui en adelante copia
Dim CnXn As ADODB.Connection
Dim RecSql As ADODB.Recordset
Private Sub Cmd_Click()
Habilitarcajas False
Limpiar
Modificar = False
Habilitarbotones False, True
End Sub
Private Sub cmdCancelar_Click()
Habilitarbotones True, False
Habilitarcajas True
Limpiar
End Sub
Private Sub cmdmodificar_Click()
Habilitarcajas False
Modificar = True
Habilitarbotones False, True
End Sub
Private Sub cmdNuevo_Click()
Habilitarcajas False
Limpiar
Modificar = False
Habilitarbotones False, True
End Sub
Private Sub cmdSalir_Click()
Unload Me
End Sub
Private Sub cmdguardar_Click()
If txtCedula.Text = "" Then MsgBox "El Campo Cedula no Puede estar Vacio", vbInformation, "Aviso": txtCedula.SetFocus: Exit Sub
If txtLugar.Text = "" Then MsgBox "El Campo Lugar de Expedicion no Puede estar Vacio", vbInformation, "Aviso": txtLugar.SetFocus: Exit Sub
If txtNombres.Text = "" Then MsgBox "El Campo Nombres no Puede estar Vacio", vbInformation, "Aviso": txtNombres.SetFocus: Exit Sub
If txtApellidos.Text = "" Then MsgBox "El Campo Apellidos no Puede estar Vacio", vbInformation, "Aviso": txtApellidos.SetFocus: Exit Sub
If txtFecha.Text = "" Then MsgBox "El Campo Fecha de Nacimiento no Puede estar Vacio", vbInformation, "Aviso": txtFecha.SetFocus: Exit Sub
If Modificar = False Then
'Base.Execute
Set RecSql = New ADODB.Recordset
If Not txtRetiro.Text = "" Then
 RecSql.Open "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'" & _
          "'" & txtLugar.Text & "','" & _
          "'" & txtNombres.Text & "','" & _
          "'" & txtApellidos.Text & "','" & _
          "'" & txtFecha.Text & "','" & _
          "'" & txtIngreso.Text & "','" & _
          "'" & txtRetiro.Text & "','" & _
          "'" & sexo.Text & "')", CnXn, adOpenKeyset, adLockOptimistic 'doy por hecho que este es un combobox
 Else
 RecSql.Open "INSERT INTO Empleados (Cedula,Lugar_Expedicion,Nombres,Apellidos,Fecha_Nacimiento,Fecha_Ingreso,Fecha_Retiro,sexo) " & _
          "VALUES" & _
          " ('" & txtCedula.Text & "'," & _
          "'" & txtLugar.Text & "'," & _
          "'" & txtNombres.Text & "'," & _
          "'" & txtApellidos.Text & "'," & _
          "'" & txtFecha.Text & "'," & _
          "'" & txtIngreso.Text & "'," & _
          "Null," & _
          "'" & sexo.Text & "')", CnXn, adOpenKeyset, adLockOptimistic 'doy por hecho que este es un combobox
 End If
 MsgBox "Datos ingresados.", vbInformation, "Nuevo registro."
Else
  Set RecSql = New ADODB.Recordset
  If Not txtRetiro.Text = "" Then
   RecSql.Open "UPDATE Empleados Set Cedula = '" & txtCedula.Text & "'," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro ='" & txtRetiro.Text & "'," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & "", CnXn, adOpenKeyset, adLockOptimistic
  Else
   RecSql.Open "UPDATE Empleados Set Cedula = '" & txtCedula.Text & "'," & _
                                      " Lugar_Expedicion = '" & txtLugar.Text & "'," & _
                                      " Nombres = '" & txtNombres.Text & "'," & _
                                      " Apellidos = '" & txtApellidos.Text & "'," & _
                                      " Fecha_Nacimiento = '" & txtFecha.Text & "'," & _
                                      " Fecha_Ingreso = '" & txtIngreso.Text & "'," & _
                                      " Fecha_Retiro = Null," & _
                                      " Sexo = '" & sexo.Text & "'" & _
                                      " where IdEmpleados = " & lblcodigo.Caption & "", CnXn, adOpenKeyset, adLockOptimistic
  End If
  MsgBox "Datos actualizados.", vbInformation, "Actualizacion de datos."
End If
Habilitarcajas True
Habilitarbotones True, False
End Sub
Sub Limpiar()
txtCedula.Text = ""
txtLugar.Text = ""
txtNombres.Text = ""
txtApellidos.Text = ""
txtFecha.Text = ""
txtIngreso.Text = ""
txtRetiro.Text = ""
lbltrabajo.Caption = ""
lbledad.Caption = ""
txtCedula.SetFocus
End Sub
Public Sub Habilitarcajas(estado As Boolean)
txtCedula.Locked = estado
txtLugar.Locked = estado
txtNombres.Locked = estado
txtApellidos.Locked = estado
txtFecha.Locked = estado
txtIngreso.Locked = estado
txtRetiro.Locked = estado
End Sub
Private Sub Form_Load()
Set CnXn = New ADODB.Connection
CnXn.Provider = "Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\LABORAL.mdb;Jet OLEDB:Database Password=false;"
CnXn.Open
Habilitarcajas True
Habilitarbotones True, False
sexo.AddItem "Masculino"
sexo.AddItem "Femenino"
sexo.ListIndex = 0
End Sub
Public Sub Habilitarbotones(estado1 As Boolean, estado2 As BookmarkEnum)
cmdNuevo.Enabled = estado1
cmdModificar.Enabled = estado1
cmdGuardar.Enabled = estado2
cmdCancelar.Enabled = estado2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Empleados
Set EmpleadosForm.grillaEmpleados.DataSource = RSEmpleados
EmpleadosForm.CerrarGrilla
End Sub
Private Sub sexo_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Nuevamente muchas gracias por su ayuda, su respuesta fue oportuna y ya analice todos los datos y pude determinar lo que me hacia surgir el error.
Espero seguir contando con su ayuda en una próxima oportunidad.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas