Artículos
Public rng1 As Range
Private Sub UserForm_Initialize()
Me.cboinventa.AddItem "SI"
Me.cboinventa.AddItem "NO"
Me.cboestatus.AddItem "ACTIVO"
Me.cboestatus.AddItem "INACTIVO"
End Sub
Private Sub txtclave_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If Me.txtopera.Text = "2" Then
Me.txtclave.Enabled = False
Me.cmdaceptar.Enabled = True
'Buscamos producto
Set rng1 = Hoja1.Range("A:A").Find(What:=Me.txtclave.Text, LookAt:=xlWhole, LookIn:=xlValues)
If rng1 Is Nothing Then
MsgBox "El producto no existe", vbOKOnly + vbInformation, "No encontrado"
Me.txtclave.Enabled = True
Else
Me.txtclave.Text = Hoja1.Range("A" & rng1.Row)
Me.txtunidad.Text = Hoja1.Range("B" & rng1.Row)
Me.txtnombre.Text = Hoja1.Range("C" & rng1.Row)
Me.txtcosto.Text = FormatNumber(Hoja1.Range("D" & rng1.Row), 4)
Me.txtprecio.Text = FormatNumber(Hoja1.Range("E" & rng1.Row), 4)
Me.cboinventa.Text = Hoja1.Range("F" & rng1.Row)
Me.txtstock.Text = FormatNumber(Hoja1.Range("G" & rng1.Row), 4)
Me.txtimagen.Text = Hoja1.Range("H" & rng1.Row)
Me.cboestatus.Text = Hoja1.Range("I" & rng1.Row)
End If
End If
End If
End Sub
Private Sub cmdexaminar_Click()
blnfile = Application.GetOpenFilename("Imagen (*.jpg*;*.bmp*;*.jpeg*),*.jpg*;*.bmp*;*.jpeg*")
If blnfile = False Then
MsgBox "Seleccione una imagen", vbOKOnly + vbExclamation, "Imagen"
Else
Me.txtimagen.Text = blnfile
End If
End Sub
Private Sub cmdaceptar_Click()
Dim lngregistros As Long
Dim blnrespuesta As Boolean
'Validamos datos
If Me.txtclave.Text = "" Then MsgBox "Clave incorrecta", vbOKOnly + vbExclamation, "Clave": Exit Sub
If Me.txtunidad.Text = "" Then MsgBox "Unidad incorrecta", vbOKOnly + vbExclamation, "Unidad": Exit Sub
If Me.txtnombre.Text = "" Then MsgBox "Nombre incorrecto", vbOKOnly + vbExclamation, "Nombre": Exit Sub
If Not IsNumeric(Me.txtcosto.Text) Or Me.txtcosto.Text = 0 Then MsgBox "Costo incorrecto", vbOKOnly + vbExclamation, "Costo": Exit Sub
If Not IsNumeric(Me.txtprecio.Text) Or Me.txtprecio.Text = 0 Then MsgBox "Precio incorrecto", vbOKOnly + vbExclamation, "Precio": Exit Sub
If Me.cboinventa.ListIndex + 1 = 0 Then MsgBox "Campo inventariable inválido", vbOKOnly + vbExclamation, "Inventariable": Exit Sub
If Me.cboestatus.ListIndex + 1 = 0 Then MsgBox "Estatus incorrecto", vbOKOnly + vbExclamation, "Estatus": Exit Sub
If Me.txtopera.Text = "1" Then
'Buscamos duplicado
Set rng1 = Hoja1.Range("A:A").Find(What:=Me.txtclave.Text, LookAt:=xlWhole, LookIn:=xlValues)
If rng1 Is Nothing Then
blnrespuesta = False
Else
blnrespuesta = True
End If
If blnrespuesta = True Then
MsgBox "La clave del producto ya existe", vbOKOnly + vbInformation, "Duplicado"
Me.txtclave.Enabled = True
Exit Sub
End If
lngregistros = Hoja1.Range("A1").CurrentRegion.Rows.Count
'Nos pregunta si deseamos guardar el registros
intrespuesta = MsgBox("¿Los datos son correctos?", vbYesNo + vbQuestion, "Antes de guardar")
'Si la respuesta es ya no continua ejecutándose la subrutina
If intrespuesta = vbNo Then
Exit Sub
Else
'Guardamos el registro
Hoja1.Cells(lngregistros + 1, 1) = Me.txtclave.Text
Hoja1.Cells(lngregistros + 1, 2) = Me.txtunidad.Text
Hoja1.Cells(lngregistros + 1, 3) = Me.txtnombre.Text
Hoja1.Cells(lngregistros + 1, 4) = FormatNumber(Me.txtcosto.Text, 4)
Hoja1.Cells(lngregistros + 1, 5) = FormatNumber(Me.txtprecio.Text, 4)
Hoja1.Cells(lngregistros + 1, 6) = Me.cboinventa.Text
Hoja1.Cells(lngregistros + 1, 7) = 0
Hoja1.Cells(lngregistros + 1, 8) = Me.txtimagen.Text
Hoja1.Cells(lngregistros + 1, 9) = Me.cboestatus.Text
MsgBox "El registro se guardó correctamente", vbOKOnly + vbInformation, "Guardado"
Me.txtopera.Text = "0"
Unload Me
End If
Else
If Me.txtopera.Text = "2" Then
'Modificamos el registro
'Hoja1.Range ("A" & rng1.Row)
Hoja1.Range("B" & rng1.Row) = Me.txtunidad.Text
Hoja1.Range("C" & rng1.Row) = Me.txtnombre.Text
Hoja1.Range("D" & rng1.Row) = FormatNumber(Me.txtcosto.Text, 4)
Hoja1.Range("E" & rng1.Row) = FormatNumber(Me.txtprecio.Text, 4)
Hoja1.Range("F" & rng1.Row) = Me.cboinventa.Text
'Hoja1.Range("G" & rng1.Row)
Hoja1.Range("H" & rng1.Row) = Me.txtimagen.Text
Hoja1.Range("I" & rng1.Row) = Me.cboestatus.Text
MsgBox "El registro se modificó correctamente", vbOKOnly + vbInformation, "Modificó"
Me.txtopera.Text = "0"
Unload Me
End If
End If
End Sub
Artículos, búsqueda por clave o nombre
Private Sub UserForm_Initialize()
EncabezadoListBox
End Sub
Private Sub EncabezadoListBox()
Dim intfila As Integer
'Definimos el número de columnas
Me.ListBox1.ColumnCount = 4
'Definimos el ancho de cada columna
Me.ListBox1.ColumnWidths = "80;300;60;60"
'Limpiar el lixtbox
ListBox1.Clear
'Agregar el elemento en las respecticas columnas
ListBox1.AddItem
intfila = ListBox1.ListCount - 1
ListBox1.Column(0, intfila) = "CLAVE"
ListBox1.Column(1, intfila) = "NOMBRE"
ListBox1.Column(2, intfila) = "PRECIO"
ListBox1.Column(3, intfila) = "SRTOCK"
End Sub
Private Sub cmdnuevo_Click()
frm_articulos.txtopera.Text = "1"
frm_articulos.cmdaceptar.Enabled = True
frm_articulos.Show
End Sub
Private Sub txtcadena_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim intcont As Integer
Dim intfila As Integer
If KeyCode = 13 Then
intregistros = Hoja1.Range("A1").CurrentRegion.Rows.Count
EncabezadoListBox
If frm_movimientos.cbotipmov.ListIndex + 1 = 1 Or frm_movimientos.cbotipmov.ListIndex + 1 = 4 Then
For intcont = 2 To intregistros
If Hoja1.Cells(intcont, 1) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 4), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
If Hoja1.Cells(intcont, 3) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 4), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
Next intcont
End If
If frm_movimientos.cbotipmov.ListIndex + 1 = 2 Or frm_movimientos.cbotipmov.ListIndex + 1 = 3 Or frm_movimientos.cbotipmov.ListIndex + 1 = 5 Then
For intcont = 2 To intregistros
If Hoja1.Cells(intcont, 1) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 5), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
If Hoja1.Cells(intcont, 3) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 5), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
Next intcont
End If
End If
Me.lblregistros.Caption = "Registros econtrados: " & Me.ListBox1.ListCount - 1
End Sub
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Me.ListBox1.ListIndex + 1 <= 1 Then Exit Sub
If KeyCode = 13 Then
frm_movimientos.txtclave.Text = Me.ListBox1.Column(0)
frm_movimientos.txtclave.SetFocus
Unload Me
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Me.ListBox1.ListIndex + 1 > 1 Then
frm_articulos.txtclave.Text = Me.ListBox1.Column(0)
frm_articulos.txtopera.Text = "2"
frm_articulos.Show
End If
End Sub
EncabezadoListBox
End Sub
Private Sub EncabezadoListBox()
Dim intfila As Integer
'Definimos el número de columnas
Me.ListBox1.ColumnCount = 4
'Definimos el ancho de cada columna
Me.ListBox1.ColumnWidths = "80;300;60;60"
'Limpiar el lixtbox
ListBox1.Clear
'Agregar el elemento en las respecticas columnas
ListBox1.AddItem
intfila = ListBox1.ListCount - 1
ListBox1.Column(0, intfila) = "CLAVE"
ListBox1.Column(1, intfila) = "NOMBRE"
ListBox1.Column(2, intfila) = "PRECIO"
ListBox1.Column(3, intfila) = "SRTOCK"
End Sub
Private Sub cmdnuevo_Click()
frm_articulos.txtopera.Text = "1"
frm_articulos.cmdaceptar.Enabled = True
frm_articulos.Show
End Sub
Private Sub txtcadena_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim intcont As Integer
Dim intfila As Integer
If KeyCode = 13 Then
intregistros = Hoja1.Range("A1").CurrentRegion.Rows.Count
EncabezadoListBox
If frm_movimientos.cbotipmov.ListIndex + 1 = 1 Or frm_movimientos.cbotipmov.ListIndex + 1 = 4 Then
For intcont = 2 To intregistros
If Hoja1.Cells(intcont, 1) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 4), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
If Hoja1.Cells(intcont, 3) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 4), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
Next intcont
End If
If frm_movimientos.cbotipmov.ListIndex + 1 = 2 Or frm_movimientos.cbotipmov.ListIndex + 1 = 3 Or frm_movimientos.cbotipmov.ListIndex + 1 = 5 Then
For intcont = 2 To intregistros
If Hoja1.Cells(intcont, 1) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 5), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
If Hoja1.Cells(intcont, 3) Like "*" & Me.txtcadena.Value & "*" Then
Me.ListBox1.AddItem
intfila = Me.ListBox1.ListCount - 1
Me.ListBox1.Column(0, intfila) = Hoja1.Cells(intcont, 1)
Me.ListBox1.Column(1, intfila) = Hoja1.Cells(intcont, 3)
Me.ListBox1.Column(2, intfila) = Format(Hoja1.Cells(intcont, 5), "##,##0.00")
Me.ListBox1.Column(3, intfila) = Format(Hoja1.Cells(intcont, 7), "##,##0.00")
End If
Next intcont
End If
End If
Me.lblregistros.Caption = "Registros econtrados: " & Me.ListBox1.ListCount - 1
End Sub
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Me.ListBox1.ListIndex + 1 <= 1 Then Exit Sub
If KeyCode = 13 Then
frm_movimientos.txtclave.Text = Me.ListBox1.Column(0)
frm_movimientos.txtclave.SetFocus
Unload Me
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Me.ListBox1.ListIndex + 1 > 1 Then
frm_articulos.txtclave.Text = Me.ListBox1.Column(0)
frm_articulos.txtopera.Text = "2"
frm_articulos.Show
End If
End Sub
No hay comentarios.:
Publicar un comentario