Empty date field when it is not

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm creating a "Database" in Excel, for that I created a Form for users to register

For this Form I created a procedure to check if the fields contain invalid data or if the textboxes are empty

the problem is that even if a specific "Textbox" is not empty, the program displays the error message of that same "Textbox"


Code:
Private Sub bt_seguinte_Click()

Dim senha_verify_register

lb_erro_nome_completo.Visible = False
lb_erro_nome_usuario.Visible = False
lb_erro_senha.Visible = False
lb_erro_confirmar_senha.Visible = False

Select Case True

Case Trim(txt_nome_completo) = "" Or IsNumeric(txt_nome_completo) And Trim(txt_nome_usuario) = "" And Trim(txt_senha) = "" And Trim(txt_confirmar_senha) = ""
    If Trim(txt_nome_completo) = "" Then
        lb_erro_nome_completo.Visible = True

    ElseIf IsNumeric(txt_nome_completo) Then
        lb_erro_nome_completo.Visible = True
        lb_erro_nome_completo.Caption = "*Caracteres Inválidos"

    End If

    lb_erro_nome_usuario.Visible = True
    lb_erro_senha.Visible = True
    lb_erro_confirmar_senha.Visible = True
    
    MsgBox "1"
    
    
Case Trim(txt_nome_completo) = "" Or IsNumeric(txt_nome_completo) And Trim(txt_nome_usuario) = "" And Trim(txt_senha) = ""
    If Trim(txt_nome_completo) = "" Then
        lb_erro_nome_completo.Visible = True
        
    ElseIf IsNumeric(txt_nome_completo) Then
        lb_erro_nome_completo.Visible = True
        lb_erro_nome_completo.Caption = "*Caracteres Inválidos"
        
    End If
    
    lb_erro_nome_usuario.Visible = True
    lb_erro_senha.Visible = True
    
    MsgBox "2"


Shouldn't "msgbox" have a value of 2?

Capturar.JPG
 
You need to change the order since the code will stop with the first matching set of criteria.
And for this case how would I have to put the parentheses?

VBA Code:
Select Case True
   
Case Trim(tb_morada) = "" And Trim(tb_cod_postal) = "" Or (Not IsNumeric(Len(tb_cod_postal) = 1) Or Not IsNumeric(Len(tb_cod_postal) = 2) Or Not IsNumeric(Len(tb_cod_postal) = 3) Or Not IsNumeric(Len(tb_cod_postal) = 4) Or Not IsNumeric(Len(tb_cod_postal) = 6) Or Not IsNumeric(Len(tb_cod_postal) = 7) Or Not IsNumeric(Len(tb_cod_postal) = 8)) And Trim(data_nasc) = "" Or Not IsNumeric(tb_data_nasc) And cb_sexo.ListIndex = -1 Or Trim(cb_sexo) = ""
    If Trim(tb_cod_postal) = "" Then
        lb_erro_cod_postal.Visible = True
       
    ElseIf Not IsNumeric(Len(tb_cod_postal) = 1) Or Not IsNumeric(Len(tb_cod_postal) = 2) Or Not IsNumeric(Len(tb_cod_postal) = 3) Or Not IsNumeric(Len(tb_cod_postal) = 4) Or Not IsNumeric(Len(tb_cod_postal) = 6) Or Not IsNumeric(Len(tb_cod_postal) = 7) Or Not IsNumeric(Len(tb_cod_postal) = 8) Then
        lb_erro_cod_postal.Visible = True
        lb_erro_cod_postal.Caption = "*Caracteres Inválidos"
       
    End If
       
    If cb_sexo.ListIndex = -1 Then
        lb_erro_sexo.Visible = True
        lb_erro_sexo.Caption = "*Opção Inválida"
       
    ElseIf Trim(cb_sexo) = "" Then
        lb_erro_sexo.Visible = True
       
    End If
   
    If Not IsNumeric(tb_data_nasc) Then
        lb_erro_data_nasc.Visible = True
        lb_erro_data_nasc.Caption = "*Caracteres Inválidos"
       
    ElseIf Trim(tb_data_nasc) = "" Then
        lb_erro_data_nasc.Visible = True
       
    End If
   
    lb_erro_morada.Visible = True


the purpose is to not allow characters 1,2,3,4,6,7 and 8 to be non-numeric characters


Capturar_ee.JPG
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top