Sei sulla pagina 1di 6

BOTON INSERTAR

Dim strBuscado As String


Dim Encontrado As Range
Worksheets("BASE DE DATOS").Activate Activa Un Libro
Range("A7").Activate Selecciona Una Celda
strBuscado = Trim(TextBox1.Text) Valor Buscado
'Verificamos que no est vacio
If strBuscado <> "" Then
'Buscamos el valor
Set Encontrado = Sheets("BASE DE DATOS").Range("A8:A100").Find(strBuscado)
If Not Encontrado Is Nothing Then
'Si lo encontro muestra los datos en las cajas
MsgBox "El Trabajador ya se encuentra en la base de datos"
Else
'ingresa a la base de datos
Do While Not IsEmpty(ActiveCell) 'ciclo para buscar la celda vacia
ActiveCell.Offset(1, 0).Activate
Loop
Condicion
If TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" And TextBox5.Text <> ""
And TextBox4.Text <> "" And TextBox5.Text <> "" And TextBox6.Text <> "" And TextBox7.Text <>
"" And TextBox8.Text <> "" And ComboBox1.Text <> "" And ComboBox2.Text <> "" And
ComboBox3.Text <> "" Then
inserta la informacion en la hoja
With ActiveCell
.Offset(0, 0).Value = TextBox1.Text
.Offset(0, 1).Value = TextBox2.Text
.Offset(0, 2).Value = TextBox3.Text
.Offset(0, 3).Value = TextBox4.Text
.Offset(0, 4).Value = TextBox5.Text
.Offset(0, 5).Value = ComboBox3.Text
.Offset(0, 6).Value = TextBox6.Text
.Offset(0, 7).Value = TextBox7.Text
.Offset(0, 8).Value = TextBox8.Text
.Offset(0, 9).Value = ComboBox1.Text
.Offset(0, 10).Value = ComboBox2.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
MsgBox "DATOS INGRESADOS"
End With
ActiveCell.Offset(1#).Activate 'pasa a la siguiente fila
MsgBox "DATOS INSERTADOS", vbInformation, "ACCION"
Else
MsgBox "DATOS NO COMPLETOS", vbInformation, "ACCION"
End If
End If
'Liberamos la memoria
Set Encontrado = Nothing
Else
'Notifica que no se proporciono dato a insertar
MsgBox "No hay nada que insertar"
End If

BOTON GUARDAR
Dim strBuscado As String
Dim Encontrado As Range
'Solicitamos un valor a buscar
strBuscado = Trim(TextBox1.Text)
'Verificamos que no este vacio
If strBuscado <> "" Then
'Buscamos el valor
Set Encontrado = Sheets("BASE DE DATOS").Range("A8:A100").Find(strBuscado)
Encontrado.Activate
If Not Encontrado Is Nothing Then
'Si lo encontro muestra los datos en las cajas
If TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" And TextBox5.Text <> ""
And TextBox4.Text <> "" And TextBox5.Text <> "" And TextBox6.Text <> "" And TextBox7.Text <>
"" And TextBox8.Text <> "" And ComboBox1.Text <> "" And ComboBox2.Text <> "" And
ComboBox3.Text <> "" Then
With ActiveCell
.Offset(0, 0).Value = TextBox1.Text
.Offset(0, 1).Value = TextBox2.Text

.Offset(0, 2).Value = TextBox3.Text


.Offset(0, 3).Value = TextBox4.Text
.Offset(0, 4).Value = TextBox5.Text
.Offset(0, 5).Value = ComboBox3.Text
.Offset(0, 6).Value = TextBox6.Text
.Offset(0, 7).Value = TextBox7.Text
.Offset(0, 8).Value = TextBox8.Text
.Offset(0, 9).Value = ComboBox1.Text
.Offset(0, 10).Value = ComboBox2.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
MsgBox "DATOS ACTUALIZADOS"
End With
End If
End If
End If
GUARDAR.Enabled = False
EDITAR.Enabled = False
ELIMINAR.Enabled = False
INSERTAR.Enabled = True
TextBox1.Enabled = True
BOTON BUSCAR
Dim strBuscado As String
Dim Encontrado As Range
Worksheets("BASE DE DATOS").Activate
Range("A7").Activate
strBuscado = Trim(TextBox1.Text)
'Verificamos que no est vacio
If strBuscado <> "" Then
'Buscamos el valor
Set Encontrado = Sheets("BASE DE DATOS").Range("A8:A100").Find(strBuscado)

If Not Encontrado Is Nothing Then


'Si lo encontro muestra los datos en las cajas
TextBox2.Text = Encontrado.Offset(0, 1).Value
TextBox3.Text = Encontrado.Offset(0, 2).Value
TextBox4.Text = Encontrado.Offset(0, 3).Value
TextBox5.Text = Encontrado.Offset(0, 4).Value
TextBox6.Text = Encontrado.Offset(0, 6).Value
ComboBox3.Text = Encontrado.Offset(0, 5).Value
TextBox7.Text = Encontrado.Offset(0, 7).Value
TextBox8.Text = Encontrado.Offset(0, 8).Value
ComboBox1.Text = Encontrado.Offset(0, 9).Value
ComboBox2.Text = Encontrado.Offset(0, 10).Value
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox6.Enabled = False
TextBox7.Enabled = False
TextBox8.Enabled = False
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox3.Enabled = False
INSERTAR.Enabled = False
GUARDAR.Enabled = True
EDITAR.Enabled = True
ELIMINAR.Enabled = True
Else
'Notifica que no encontro nada
MsgBox "Valor no encontrado"
End If
'Liberamos la memoria
Set Encontrado = Nothing
Else
'Notifica que no se proporciono dato a buscar
MsgBox "No hay nada que buscar"
'INSERTAR.Enabled = True
End If
'MODIFICAR.Enabled = True
BOTON ELIMINAR
Worksheets("BASE DE DATOS").Activate

Range("A7").Activate
For i = 1 To 1000
If Range("A" & i).Value = TextBox1.Text Then
Rows(i).Delete
i=i-1
End If
Next i
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
GUARDAR.Enabled = False
EDITAR.Enabled = False
ELIMINAR.Enabled = False
INSERTAR.Enabled = True
TextBox1.Enabled = True
MsgBox "DATOS ELIMINADOS"
BOTON SALIR

If MsgBox("Quiere salir de esta aplicacin ", vbQuestion + vbYesNo, "ULTIMA PALABRA") = vbYes
Then
ActiveWorkbook.Save
Application.Quit
End If

Potrebbero piacerti anche