account validation crashed in vba macro

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I have a macro to check if the user has entered the "Username" and the "Password" correctly depending on the data present in another excel file, it happens that I enter the data correctly and the program detects that the password or user is wrong


VBA Code:
Private Sub bt_seguinte_Click()

'Oculta as mensagens de erro
lb_erro_usuario.Visible = False
lb_erro_senha.Visible = False


'Inicio da função "Case"
Select Case True
   
'Se ambas as "textboxes" estiverem vazias então...
Case Trim(tb_usuario) = "" And Trim(tb_senha) = ""

    'Ambas as mensagens de erro são mostradas
    lb_erro_usuario.Visible = True
    lb_erro_senha.Visible = True
   
'Se a "textbox" do "Usuário" estiver vazia então...
Case Trim(tb_usuario) = ""

    'A mensagem de erro do "Usuário" é mostrada
    lb_erro_usuario.Visible = True
   
'Se a "textbox" da "Senha" estiver vazia então...
Case Trim(tb_senha) = ""
   
    'A mensagem de erro da "Senha" é mostrada
    lb_erro_senha.Visible = True
   
'Senão...
Case Else

Application.ScreenUpdating = False

Workbooks(OtherBookPath).Sheets("Usuários").Activate

contar_usuarios = Cells(Rows.Count, "B").End(xlUp).Row

For c = 2 To contar_usuarios

    Select Case True
   
    Case tb_usuario.Value = Cells(c, 4).Value
        If tb_senha.Value = ActiveCell.Offset(0, 1).Value Then
            nome_usuario = tb_usuario.Value
            senha = tb_senha.Value
            Unload Me
            Library_Choose.Show

        Else
            lb_erro_senha.Visible = True
            lb_erro_senha.Caption = "*Senha ou Nome de Usuário incorretos"
            Exit For
           
        End If
       
    Case c = contar_usuarios And tb_usuario.Value <> Cells(c, 4).Value
        lb_erro_senha.Visible = True
        lb_erro_senha.Caption = "*Senha ou Nome de Usuário incorretos"
       
    End Select

Next c

Workbooks(CurrentBookPath).Activate
Application.ScreenUpdating = True

End Select
End Sub


app.JPG



I transferred the backup of the previous file I had and the code is similar and works, can someone help me?


VBA Code:
Workbooks(OtherBookPath).Sheets("Usuários").Activate

contar_usuarios = Cells(Rows.Count, "D").End(xlUp).Row

For c = 2 To contar_usuarios

    Cells(c, 4).Select
    
    Select Case True
    
    Case nome_usuario = ActiveCell
        If senha = ActiveCell.Offset(0, 1) Then
            Unload Me
            Library_Choose.Show

        Else
            lb_erro_senha.Visible = True
            lb_erro_senha.Caption = "*Senha ou Nome de Usuário incorretos"
            Exit For
            
        End If
        
    Case c = contar_usuarios And nome_usuario <> ActiveCell
        lb_erro_senha.Visible = True
        lb_erro_senha.Caption = "*Senha ou Nome de Usuário incorretos"
              
    Case nome_usuario <> ActiveCell
    End Select

Next c

Workbooks(CurrentBookPath).Activate
Application.ScreenUpdating = True

End Select
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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