Está en la página 1de 3

BOTONES GUARDAR (PARA DATOS CON LLAVES PRIMARIAS)

ESTOS SE ABREN CUANDO SE HACE 2 CLICKS SOBRE BOTONES EN EL FORMULARIO

Private Sub btnGuardarOtro_Click()


If txtPilotoID.Text <> Empty And txtNombresPiloto.Text <> Empty And
txtApellidosPiloto.Text <> Empty Then
GuardarPiloto
txtPilotoID = Empty
txtNombresPiloto = Empty
txtApellidosPiloto = Empty
Else
MsgBox "Debe llenar los datos requeridos"
End If
End Sub

------

Private Sub btnGuardarPiloto_Click()


If txtPilotoID.Text <> Empty And txtNombresPiloto.Text <> Empty And
txtApellidosPiloto.Text <> Empty Then
GuardarPiloto
Unload Me
Else
MsgBox "Debe llenar los datos requeridos"
End If
End Sub

-------------

Sub GuardarPiloto()
Sheets("Piloto").Select
Range("E8").EntireRow.Insert
Range("E8") = txtPilotoID.Value
Range("F8") = txtNombresPiloto.Value
Range("G8") = txtApellidosPiloto.Value
End Sub

___________________________________________________________________________________
______________________________________________

CODIGO PARA ABRIR FORMULARIO Y FILTRADO


ESTE SE ABRE EN CLICK DERECHO SOBRE LA HOJA Y "VER CODIGO"

Sub llamarFormularioPiloto()
frmPiloto.Show
End Sub

---------

Private Sub txtBusquedaPilotos_Change()


criterio = ""
If txtBusquedaPilotos <> "" Then
criterio = "*" & Sheets("Piloto").txtBusquedaPilotos.Text & "*"
Range("E8").AutoFilter Field:=2, Criteria1:=criterio
Else
Sheets("Piloto").Range("E8").AutoFilter
Sheets("Piloto").Range("E8").AutoFilter
End If
End Sub

...................................................................................
..........................................

BOTON GUARDAR EN PARA LLAVES FORANEAS

Private Sub btnGuardar_Click()


If txtID.Text = Empty Or txtNombre.Text = Empty Or txtPrecioCompra.Text = Empty
Or txtRentabilidad.Text = Empty Or cmbProveedor.ListIndex = -1 Or
cmbCategoria.ListIndex = -1 Then
MsgBox "Debe de llenar los datos requeridos"
' bloque en caso se cumpla una de las condiciones
Else
' bloque en caso no se cumpla ninguna de las condiciones
Sheets("Productos").Select
Range("B8").EntireRow.Insert
Range("B8") = txtID.Text
Range("C8") = cmbProveedor.Value
Range("E8") = cmbCategoria.Value
Range("F8") = txtNombre.Text
Range("J8") = txtPrecioCompra.Text
porcentaje = txtRentabilidad.Value / 100 ' 50 / 100 = 0.5
Range("K8") = porcentaje
' Codigo para limpiar
txtID.Text = Empty
cmbProveedor = Empty
cmbCategoria = Empty
txtNombre = Empty
txtPrecioCompra = Empty
txtRentabilidad = Empty
End If
End Sub

___________________________________________________________________________________
___________________________________________________________________________________
__

BOTON SALIR

Private Sub btnSalir_Click()


Unload Me
End Sub

___________________________________________________________________________________
___________________________________________________________________________________
________

AGREGAR CATEGORIAS O PROVEEDORES

Private Sub UserForm_Activate()


' CARGAR LISTADO DE CATEGORIAS
cmbCategoria.AddItem ("Accesorios")
cmbCategoria.AddItem ("Audio")
cmbCategoria.AddItem ("Computadoras")
cmbCategoria.AddItem ("Teclados")
' CARGAR COMBOBOX PROVEEDORES
cmbProveedor.RowSource = "PROVEEDORES" ' La fuente del combobox va a ser la
tabla PROVEEDORES
cmbProveedor.ColumnCount = 2 ' Seleccionará los primeros 2 campos de la tabla
End Sub

___________________________________________________________________________________
___________________________________________________________________________________
_____________

MOSTRAR FORMULARIO

Sub llamarFormularioProducto()
frmProducto.Show
End Sub

También podría gustarte