3. REGISTRO DE CLIENTES
CÓDIGOFORMULARIOS
AGREGAR
Option Explicit
Dim ArchivoIMG As String
Private Sub cmd_Agregar_Click()
Dim i As Integer
If cbo_Nombre.Text= "" Then
MsgBox"Nombre inválido",vbInformation+ vbOKOnly
cbo_Nombre.SetFocus
ExitSub
End If
If Not (Mid(cbo_Nombre.Text,1,1) Like "[a-z]" OrMid(cbo_Nombre.Text,1,1) Like "[A-Z]") Then
MsgBox "Nombre inválido",vbInformation+ vbOKOnly cbo_Nombre.SetFocus
ExitSub
End If
4. REGISTRO DE CLIENTES
For i = 2 To Len(cbo_Nombre.Text)
IfMid(cbo_Nombre.Text,i,1) Like "#" Then
MsgBox "Nombre inválido",vbInformation+ vbOKOnly
cbo_Nombre.SetFocus
Exit Sub
End If
Next
Sheets("Clientes").Activate
Dim fCliente AsInteger fCliente =
nCliente(cbo_Nombre.Text)
If fCliente =0 Then
Do While NotIsEmpty(ActiveCell)
ActiveCell.Offset(1,0).Activate ' si el registro no existe,se va al final.
Loop
5. REGISTRO DE CLIENTES
Else
Cells(fCliente,1).Select ' cuando ya existe el registro,cumple esta condición.
End If
'Aqui es cuando agregamos o modificamosel registro
Application.ScreenUpdating=False
ActiveCell = cbo_Nombre
ActiveCell.Offset(0,1) = txt_Direccion
ActiveCell.Offset(0,2) = txt_Telefono
ActiveCell.Offset(0,3) = txt_ID
ActiveCell.Offset(0,4) = txt_Email
ActiveCell.Offset(0,5) = ArchivoIMG
txt_Direccion= Empty
txt_Telefono= Empty
txt_ID = Empty txt_Email
= Empty cbo_Nombre =
Empty
6. REGISTRO DE CLIENTES
Application.ScreenUpdating
= True
cbo_Nombre.SetFocus
End Sub
ELIMINAR
Private Subcmd_Eliminar_Click() Dim
fCliente AsInteger fCliente=
nCliente(cbo_Nombre.Text)
If fCliente=0 Then
MsgBox "El cliente que ustedquiere eliminarnoexiste",vbInformation+vbOKOnly
cbo_Nombre.SetFocus
ExitSub
End If
7. REGISTRO DE CLIENTES
If MsgBox("¿Seguroque quiere eliminareste cliente?",vbQuestion+vbYesNo) =vbYesThen Cells(fCliente,1).Select
ActiveCell.EntireRow.Delete
MsgBox "Cliente eliminado", vbInformation+vbOKOnly
cbo_Nombre.SetFocus
End If
End Sub
CERRAR
Private Subcmd_Cerrar_Click()
End
End Sub
COMBOBOX o CUADRO COMBINADO cbo_Nombre
Private Subcbo_Nombre_Change()
On Error Resume Next
8. REGISTRO DE CLIENTES
If nCliente(cbo_Nombre.Text) <>0 Then
Sheets("Clientes").Activate
Cells(cbo_Nombre.ListIndex +2, 1).Select
txt_Direccion=ActiveCell.Offset(0,1)
txt_Telefono=ActiveCell.Offset(0,2)
txt_ID = ActiveCell.Offset(0,3) txt_Email =
ActiveCell.Offset(0,4)
fotografia.Picture =LoadPicture("")
fotografia.Picture =LoadPicture(ActiveCell.Offset(0,5))
ArchivoIMG= ActiveCell.Offset(0,5)
Else
9. REGISTRO DE CLIENTES
txt_Direccion="" txt_Telefono
= "" txt_ID = "" txt_Email = ""
ArchivoIMG= "" fotografia.Picture
= LoadPicture("")
End If
End Sub
Private Subcbo_Nombre_Enter()
CargarLista
End SubSub
CargarLista()
cbo_Nombre.Clear
Sheets("Clientes").Select
Range("A2").Select Do While Not
IsEmpty(ActiveCell)
cbo_Nombre.AddItemActiveCell.Value
ActiveCell.Offset(1,0).Select
Loop
10. REGISTRO DE CLIENTES
End Sub
SubLimpiarFormulario()
CargarLista
cbo_Nombre = ""
txt_Direccion=""
txt_Telefono=""
txt_ID = "" txt_Email
= ""
ArchivoIMG= "" End
Sub
cmd_Imagen
Private Sub cmd_Imagen_Click()
On Error Resume Next
ArchivoIMG = Application.GetOpenFilename("Imágenes jpg,*.jpg,Imágenes bmp,*.bmp", 0, "Seleccionar Imágen para Reegistro de
Clientes")
11. REGISTRO DE CLIENTES
fotografia.Picture = LoadPicture("")
fotografia.Picture = LoadPicture(ArchivoIMG)
End Sub
MÓDULO 1
Option Explicit
Sub registrar()
Load frm_Clientes
Sheets("clientes").Activate
frm_Clientes.Show
End Sub
Function nCliente(nombre As String) As Integer
Application.ScreenUpdating = False
Sheets("Clientes").Activate
Range("A2").Activate
12. REGISTRO DE CLIENTES
nCliente = 0
Do While Not IsEmpty(ActiveCell)
If nombre = ActiveCell Then
nCliente = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Function