En este vídeo se hace la validación del formulario de Datos de la Empresa y se crear el formulario de Perfil de Usuario para editar los datos de usuario es decir: El usuario puede entrar a esta ventana para editar sus datos y para el cambio de contraseña.
El botón guardar lleva el siguiente código:
Private Sub cmdGuardar_Click()
If txtNombreEmpresa.Text = "" Then
MsgBox "Debe llenar el Campo Nombre Empresa", vbExclamation, "Error"
txtNombreEmpresa.SetFocus
Exit Sub
End If
If txtPropietario.Text = "" Then
MsgBox "Debe llenar el Campo Propietario", vbExclamation, "Error"
txtPropietario.SetFocus
Exit Sub
End If
If txtNit.Text = "" Then
MsgBox "Debe llenar el Campo Nit", vbExclamation, "Error"
txtNit.SetFocus
Exit Sub
End If
If txtTelefono.Text = "" Then
MsgBox "Debe llenar el Campo Telefono", vbExclamation, "Error"
txtTelefono.SetFocus
Exit Sub
End If
If txtDireccion.Text = "" Then
MsgBox "Debe llenar el Campo Dirección", vbExclamation, "Error"
txtDireccion.SetFocus
Exit Sub
End If
If txtDescripcion.Text = "" Then
MsgBox "Debe llenar el Campo Descripción", vbExclamation, "Error"
txtDescripcion.SetFocus
Exit Sub
End If
If cmdTipoRegimen.ListIndex = 1 Then
If txtResolucion.Text = "" Then
MsgBox "Debe llenar el Campo Resolución", vbExclamation, "Error"
txtResolucion.SetFocus
Exit Sub
End If
If IsDate(txtFechaApro.Text) = False Then
MsgBox "Escriba una Fecha de Aprovación válida", vbExclamation, "Error"
txtFechaApro.SetFocus
Exit Sub
End If
If txtRango1.Text = "" Then
MsgBox "Debe llenar el Campo Rango 1", vbExclamation, "Error"
txtRango1.SetFocus
Exit Sub
End If
If txtRango2.Text = "" Then
MsgBox "Debe llenar el Campo Rango 2", vbExclamation, "Error"
txtRango2.SetFocus
Exit Sub
End If
If txtFacturarDesde.Text = "" Then
MsgBox "Debe llenar el Campo Facturar Desde", vbExclamation, "Error"
txtFacturarDesde.SetFocus
Exit Sub
End If
End If
Call GuardarDatos
Call DesabilitarControles
End Sub
Para validar y que el campo solo reciba números se utiliza la siguiente función:
Function SoloNumeros(Key_p) As Boolean
If Key_p = 13 Or Key_p = 8 Or Key_p = 46 Or Key_p = 44 Then
SoloNumeros = True
Exit Function
End If
If Key_p >= 48 And Key_p <= 57 Then
SoloNumeros = True
Else
SoloNumeros = False
End If
End Function
Validación del campo Rango 1
Private Sub txtRango1_GotFocus()
Call DeseleccionarTexBox(Me)
Call SeleccionarTextBox(txtRango1)
End Sub
Private Sub txtRango1_KeyPress(KeyAscii As Integer)
If SoloNumeros(KeyAscii) = False Then
KeyAscii = 0
End If
End Sub
Private Sub txtRango1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
txtRango2.SetFocus
End If
End Sub
Validación del campo Rango 2
Private Sub txtRango2_GotFocus()
Call DeseleccionarTexBox(Me)
Call SeleccionarTextBox(txtRango2)
End Sub
Private Sub txtRango2_KeyPress(KeyAscii As Integer)
If SoloNumeros(KeyAscii) = False Then
KeyAscii = 0
End If
End Sub
Private Sub txtRango2_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
txtFacturarDesde.SetFocus
End If
End Sub
Procedimiento para guardar los datos:
Sub GuardarDatos()
'Valdaciones
Dim Regimen As Integer
Dim FechaR As Date
Regimen = Me.cmdTipoRegimen.ListIndex
If Me.txtFechaApro.Text <> "" Then
FechaR = Me.txtFechaApro.Text
End If
Call GuardarDatosEmpresa(txtNombreEmpresa, txtPropietario.Text, txtNit, txtTelefono, txtDireccion, txtLogo, txtDescripcion, Regimen, txtResolucion, FechaR, txtRango1, txtRango2, txtFacturarDesde)
End Sub
Actualización del procedimiento LlenarDatos:
Sub LlenarDatos()
Dim RecorsetTemp As New ADODB.RecordSet
Dim Sql As String
Sql = "Select * from tblDatosEmpresa where IdEmpresa = 1"
RecorsetTemp.Open Sql, ConexionADO
If RecorsetTemp.RecordCount > 0 Then
txtNombreEmpresa.Text = RecorsetTemp("NombreEmpresa")
txtPropietario.Text = RecorsetTemp("Propietario")
txtNit.Text = RecorsetTemp("Nit")
txtTelefono.Text = RecorsetTemp("Telefonos")
txtDireccion.Text = RecorsetTemp("Direccion")
txtLogo.Text = RecorsetTemp("Logo")
If Dir(txtLogo.Text) <> "" And txtLogo.Text <> "" Then
imgLogo.Picture = LoadPicture(txtLogo.Text)
Else
imgLogo.Picture = LoadPicture(App.Path & "\logo.jpg")
End If
txtDescripcion.Text = RecorsetTemp("Descripcion")
cmdTipoRegimen.ListIndex = RecorsetTemp("Regimen")
txtResolucion.Text = RecorsetTemp("Resolucion")
txtFechaApro.Text = RecorsetTemp("FechaResol")
txtRango1.Text = RecorsetTemp("Rango1")
txtRango2.Text = RecorsetTemp("Rango2")
txtFacturarDesde.Text = RecorsetTemp("IniciarEn")
End If
End Sub
Evento Clic del Campo Regimen:
Private Sub cmdTipoRegimen_Click()
If cmdTipoRegimen.ListIndex = 0 Then
txtResolucion.Enabled = False
txtFechaApro.Enabled = False
txtRango1.Enabled = False
txtRango2.Enabled = False
txtFacturarDesde.Enabled = False
txtResolucion.Text = "0"
txtRango1.Text = "0"
txtRango2.Text = "0"
txtFacturarDesde.Text = "0"
txtFechaApro.Mask = ""
txtFechaApro.Text = ""
Else
If cmdTipoRegimen.Enabled = True Then
txtResolucion.Enabled = True
txtFechaApro.Enabled = True
txtRango1.Enabled = True
txtRango2.Enabled = True
txtFacturarDesde.Enabled = True
txtFechaApro.Mask = "##/##/####"
End If
End If
End Sub
En este vídeo explico detalladamente como elaborar la ventana y su validación.
Siguiente Lección Parte 11 Ventana de Perfil de Usuario
Total Page Visits: 6627 - Today Page Visits: 5

