You are on page 1of 4

Private Sub Bcerrar_Click() '**** Codigo del Boton Cerrar ****

Unload Me
End Sub

Private Sub Beliminar_Click() '**** Codigo del Boton Eliminar ****


Dim x As Integer
x = MsgBox("Seguro que desea Eliminar este Item?", vbQuestion + vbYesNo, "Eliminar Item")
If x <> vbYes Then Exit Sub
Selection.EntireRow.Delete
ActiveWorkbook.Save
End Sub

Private Sub Bfoto_Click() '**** Codigo del Boton Para buscar la Fotografia ****
On Error Resume Next
archivoimg = Application.GetOpenFilename("Imágenes jpg,*.jpg,Imágenes bmp,*.bmp,Imágenes
jpeg,*.jpeg", 0, "Seleccionar Imágen")
Image1.Picture = LoadPicture("")
Image1.Picture = LoadPicture(archivoimg)
Truta = (archivoimg)
If Truta.Text = "FALSO" Then
Truta = Truta2.Text
End If
End Sub
Private Sub bguardar_Click() '**** Codigo del boton Guardar ****
Sheets("Empleados").Activate

Dim fCode As Integer


fCode = nCode(Cbcode.Text)

If fCode = 0 Then '1


Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Activate ' si el registro no existe, se va al final.
Loop

With ActiveCell.EntireRow.Font
.Name = "Calibri"
.Size = 9

End With

Dim x As Integer
x = MsgBox("Seguro que Desea Ingresar este Empleado? ", vbYesNo, "Ingresar Empleado")
If x <> vbYes Then Exit Sub
'Aqui es cuando agregamos o modificamos el registro
Application.ScreenUpdating = False
ActiveCell = Cbcode
ActiveCell.Offset(0, 1) = Tnom: ActiveCell.Offset(0, 2) = The: ActiveCell.Offset(0, 3) = Thsa
ActiveCell.Offset(0, 4) = Val(Tsud.Value): ActiveCell.Offset(0, 5) = Tfecha
ActiveCell.Offset(0, 6) = Truta

Application.ScreenUpdating = True

ActiveWorkbook.Save
Cbcode.Text = Worksheets("Empleados").Range("A2")

Exit Sub
Else
Cells(fCode, 2).Select ' cuando ya existe el registro, cumple esta condición.

End If '1

With ActiveCell.EntireRow.Font
.Name = "Calibri"
.Size = 9

End With
Dim Y As Integer
Y = MsgBox("Seguro que Desea Modificar este Empleado? ", vbYesNo, "Ingresar Empleados")
If Y <> vbYes Then Exit Sub '1
'Aqui es cuando agregamos o modificamos el registro
Application.ScreenUpdating = False
ActiveCell = Cbcode
ActiveCell.Offset(0, 0) = Tnom: ActiveCell.Offset(0, 1) = The: ActiveCell.Offset(0, 2) = Thsa
ActiveCell.Offset(0, 3) = Val(Tsud.Value): ActiveCell.Offset(0, 4) = Tfecha:
ActiveCell.Offset(0, 5) = Truta

Application.ScreenUpdating = True

ActiveWorkbook.Save
Cbcode.Text = Worksheets("Empleados").Range("A2")

End Sub

Private Sub Cbcode_Change() '**** Codigo del Cuadro combinado ****


Tcod.Text = Cbcode.Text
On Error Resume Next
If nCode(Cbcode.Text) <> 0 Then

Sheets("Empleados").Activate

Cells(Cbcode.ListIndex + 2, 1).Select
Tnom = ActiveCell.Offset(0, 1): The = ActiveCell.Offset(0, 2): Thsa = ActiveCell.Offset(0, 3)
Tsud = ActiveCell.Offset(0, 4): Tfecha = ActiveCell.Offset(0, 5)
Truta3 = ActiveCell.Offset(0, 6)

Else
Tnom = "": The = "": Thsa = "": Tsal = 0: Tsud = 0: Tfecha = Date: Truta3 = Truta2.Text
End If
End Sub

Private Sub Tcod_Change() '**** Codigo del textbox de codigo ****


If IsNumeric(Tcod.Text) Then

Else
Tcod = ""
End If

Cbcode = Tcod
End Sub

Private Sub Tnom_Change() '**** Codigo del textbox nombre ****


If Tnom = "" Then
bguardar.Caption = "Guardar"
Else
bguardar.Caption = "Actualizar"
End If
End Sub
Private Sub Truta3_Change() '**** Codigo del textbox ruta3 ****
If Truta3 <> "" Then
Image1.Picture = LoadPicture(Truta3)
Else
Image1.Picture = LoadPicture(Truta2)
End If
End Sub

Private Sub Tsud_Change() '**** Codigo del textt de sueldo diario para validar que acepte solo numeros
****
If IsNumeric(Tsud.Text) Then

Else
Tsud = ""
End If
End Sub

Private Sub UserForm_Initialize() '**** Codigo del formulario ****


Dim rango, celda As Range
Set rango = Worksheets("Empleados").Range("Listado_emp")

For Each celda In rango


Cbcode.AddItem celda.Value

Next celda
Cbcode.Text = Worksheets("Empleados").Range("A2")
Tfecha = Date
End Sub

Function nCode(Codigo As String) As Integer '**** Codigo del Modulo ****


Application.ScreenUpdating = False
Sheets("Empleados").Activate
Range("A2").Activate

nCode = 0
Do While Not IsEmpty(ActiveCell)
If Codigo = ActiveCell Then
nCode = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True

End Function

You might also like