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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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?

View attachment 42511

The same is true for this case:


Capturar_2.JPG



Code:

VBA Code:
Case Trim(tb_nome_completo) = "" Or IsNumeric(tb_nome_completo) And Trim(tb_senha) = "" And Trim(tb_confirmar_senha) = ""
    If Trim(tb_nome_completo) = "" Then
        lb_erro_nome_completo.Visible = True
        
    ElseIf Not IsNumeric(tb_nome_completo) Then
        lb_erro_nome_completo.Visible = True
        lb_erro_nome_completo.Caption = "*Caracteres Inválidos"
        
    End If
    
    lb_erro_confirmar_senha.Visible = True
    lb_erro_senha.Visible = True
    MsgBox "5"
 
Upvote 0
You need to bracket your Or conditions if the result of that should be used in the And with the other criteria:

Code:
Case (Trim(txt_nome_completo) = "" Or IsNumeric(txt_nome_completo))

As a side note, I see no value in using a Select Case True construct here; nested Ifs would appear more easily understandable to me.
 
Upvote 0
Você precisa colocar suas condições Ou entre colchetes se o resultado disso deve ser usado no E com os outros critérios:

Code:
 Case (Trim (txt_nome_completo) = "" Or IsNumeric (txt_nome_completo)) [/ code]

Como uma observação lateral, não vejo nenhum valor em usar uma construção Select Case True aqui; Ifs aninhados pareceriam mais facilmente compreensíveis para mim.
[/QUOTE]
Thnaks man, I used "Case" because the verification is much faster since the "IF" values are confirmed one by one
 
Upvote 0
You need to bracket your Or conditions if the result of that should be used in the And with the other criteria:

Code:
Case (Trim(txt_nome_completo) = "" Or IsNumeric(txt_nome_completo))

As a side note, I see no value in using a Select Case True construct here; nested Ifs would appear more easily understandable to me.
a function still doesn't work..

Code:

VBA Code:
Case (Trim(tb_nome_completo) = "" Or IsNumeric(tb_nome_completo)) And Trim(tb_senha) = ""
    If Trim(tb_nome_completo) = "" Then
        lb_erro_nome_completo.Visible = True
        
    ElseIf Not IsNumeric(tb_nome_completo) Then
        lb_erro_nome_completo.Visible = True
        lb_erro_nome_completo.Caption = "*Caracteres Inválidos"
        
    End If
    
    lb_erro_senha.Visible = True
    MsgBox "4"
    
    
    
    
Case (Trim(tb_nome_completo) = "" Or IsNumeric(tb_nome_completo)) And Trim(tb_senha) = "" And Trim(tb_confirmar_senha) = ""
    If Trim(tb_nome_completo) = "" Then
        lb_erro_nome_completo.Visible = True
        
    ElseIf Not IsNumeric(tb_nome_completo) Then
        lb_erro_nome_completo.Visible = True
        lb_erro_nome_completo.Caption = "*Caracteres Inválidos"
        
    End If
    
    lb_erro_confirmar_senha.Visible = True
    lb_erro_senha.Visible = True
    MsgBox "11"


Capturar_3.JPG


the program should display "11"
 
Upvote 0
Why? It matches the first set of criteria since nome completo and senha are both empty.
 
Upvote 0
Why? It matches the first set of criteria since nome completo and senha are both empty.
will i have to change the order of the code oui is it an error in the code?
 
Upvote 0
You need to change the order since the code will stop with the first matching set of criteria.
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

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