0% encontró este documento útil (0 votos)
76 vistas5 páginas

Manejo de Clientes en VBA

Este documento contiene subrutinas en Visual Basic para agregar, eliminar y modificar registros de clientes en una hoja de cálculo. La subrutina cmd_Agregar_Click() valida los campos del formulario, busca el registro del cliente y agrega la información. La subrutina cmd_Eliminar_Click() encuentra y elimina el registro seleccionado. La subrutina cbo_Nombre_Change() carga los datos del cliente seleccionado en los campos del formulario.

Cargado por

oame
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
76 vistas5 páginas

Manejo de Clientes en VBA

Este documento contiene subrutinas en Visual Basic para agregar, eliminar y modificar registros de clientes en una hoja de cálculo. La subrutina cmd_Agregar_Click() valida los campos del formulario, busca el registro del cliente y agrega la información. La subrutina cmd_Eliminar_Click() encuentra y elimina el registro seleccionado. La subrutina cbo_Nombre_Change() carga los datos del cliente seleccionado en los campos del formulario.

Cargado por

oame
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

Private Sub cmd_Agregar_Click()

Dim i As Integer

If cbo_Nombre.Text = "" Then

MsgBox "Nombre inválido", vbInformation + vbOKOnly

cbo_Nombre.SetFocus

Exit Sub

End If

If Not (Mid(cbo_Nombre.Text, 1, 1) Like "[a-z]" Or Mid(cbo_Nombre.Text, 1, 1) Like "[A-Z]")


Then

MsgBox "Nombre inválido", vbInformation + vbOKOnly

cbo_Nombre.SetFocus

Exit Sub

End If

For i = 2 To Len(cbo_Nombre.Text)

If Mid(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 As Integer

fCliente = nCliente(cbo_Nombre.Text)

If fCliente = 0 Then

Do While Not IsEmpty(ActiveCell)


[Link](1, 0).Activate ' si el registro no existe, se va al final.

Loop

Else

Cells(fCliente, 1).Select ' cuando ya existe el registro, cumple esta condición.

End If

'Aqui es cuando agregamos o modificamos el registro

[Link] = False

ActiveCell = cbo_Nombre

[Link](0, 1) = txt_Direccion

[Link](0, 2) = txt_Telefono

[Link](0, 3) = txt_ID

[Link](0, 4) = txt_Email

[Link](0, 5) = ArchivoIMG

[Link] = True

LimpiarFormulario

cbo_Nombre.SetFocus

End Sub

Private Sub cmd_Eliminar_Click()

Dim fCliente As Integer

fCliente = nCliente(cbo_Nombre.Text)

If fCliente = 0 Then
MsgBox "El cliente que usted quiere eliminar no existe", vbInformation + vbOKOnly

cbo_Nombre.SetFocus

Exit Sub

End If

If MsgBox("¿Seguro que quiere eliminar este cliente?", vbQuestion + vbYesNo) = vbYes Then

Cells(fCliente, 1).Select

[Link]

LimpiarFormulario

MsgBox "Cliente eliminado", vbInformation + vbOKOnly

cbo_Nombre.SetFocus

End If

End Sub
Private Sub cbo_Nombre_Change()

On Error Resume Next

If nCliente(cbo_Nombre.Text) <> 0 Then

Sheets("Clientes").Activate

Cells(cbo_Nombre.ListIndex + 2, 1).Select

txt_Direccion = [Link](0, 1)

txt_Telefono = [Link](0, 2)

txt_ID = [Link](0, 3)

txt_Email = [Link](0, 4)

Else

txt_Direccion = ""

txt_Telefono = ""

txt_ID = ""

txt_Email = ""

ArchivoIMG = ""

[Link] = LoadPicture("")

End If

End Sub

Private Sub btn_Eliminar_Click() listbox

On Error GoTo Errores

[Link] ([Link]) 'Eliminar el item

[Link] = -1 ' Eliminar la "barra de selección"

For i = 0 To [Link] - 1 'Inspeccionar el índce de registros para determinar cual


es el último
Next

[Link]

Exit Sub

Errores:

MsgBox "Debe seleccionar un item"

End Sub

También podría gustarte