Sou novo na área de programação é gostaria muito de uma ajuda nesse problema:
Preciso criar um esquema para que o user possa tentar acessar a planilha 3 vezes (por exemplo) caso erre a senha e depois disso ele receberá uma mensagem para contatar o ADM.
Segue o código que eu desenvolvi, mas não está dando certo. Toda ajuda será bem vinda
Código: Selecionar todos
Private Sub CommandButton2_Click()
Dim var1, var2 As Date
var1 = Date
var2 = Time
'cont é a variável que contará a quantidade de tentativas
Dim cont As Integer
'quant é a quantidade
Dim quant As Integer
'quantas vezes poderá tentar
quant = 3
'cont contará apartir de zero
cont = 0
'volta para tentar mais uma vez
volta:
cont = cont + 1
If cont >= quant Then
MsgBox "Tentativas esgotadas, contate um adm."
TextBox1.SetFocus
Else
If CheckBox1 = False Then
If TextBox1 = "" Then
MsgBox "Digite o usuário"
Exit Sub
TextBox1.SetFocus
Else
If TextBox2 = "" Then
MsgBox "Digite a senha"
Exit Sub
TextBox2.SetFocus
End If
End If
u = 3
While (Planilha4.Cells(u, 1) <> TextBox1)
u = u + 1
If u > 100 Then
MsgBox "Usuário não cadastrado"
Exit Sub
End If
Wend
Dim G As String
G = Planilha4.Cells(u, 2).Value
If TextBox2 <> G Then
MsgBox "Senha incorreta"
GoTo volta
Else
MsgBox "Seja Bem Vindo " & TextBox1
u = 3
While (Planilha6.Cells(u, 1) <> "")
u = u + 1
Wend
Planilha6.Cells(u, 1) = TextBox1.Value
Planilha6.Cells(u, 2) = var1
Planilha6.Cells(u, 3) = var2
Planilha6.Cells(u, 4) = "Usuário"
Planilha9.Visible = xlSheetVisible
Sheets("MENU_SISTEMAS_USUARIOS").Activate
ActiveWindow.DisplayWorkbookTabs = False
Hide
End If
Else
If TextBox1 = "" Then
MsgBox "Digite o usuário"
Exit Sub
TextBox1.SetFocus
Else
If TextBox2 = "" Then
MsgBox "Digite a senha"
Exit Sub
TextBox2.SetFocus
End If
End If
u = 3
While (Planilha4.Cells(u, 4) <> TextBox1)
u = u + 1
If u > 10 Then
MsgBox "Admin. não cadastrado"
Exit Sub
End If
Wend
Dim Y As String
Y = Planilha4.Cells(u, 5).Value
If TextBox2 <> Y Then
MsgBox "Senha incorreta"
Exit Sub
Else
MsgBox "Seja Bem Vindo Admin. " & TextBox1
u = 3
While (Planilha6.Cells(u, 1) <> "")
u = u + 1
Wend
Planilha6.Cells(u, 1) = TextBox1.Value
Planilha6.Cells(u, 2) = var1
Planilha6.Cells(u, 3) = var2
Planilha6.Cells(u, 4) = "Admin."
ActiveWindow.DisplayWorkbookTabs = True
Planilha1.Visible = xlSheetVisible
Planilha2.Visible = xlSheetVisible
Planilha3.Visible = xlSheetVisible
Planilha4.Visible = xlSheetVisible
Planilha5.Visible = xlSheetVisible
Planilha6.Visible = xlSheetVisible
Planilha7.Visible = xlSheetVisible
Planilha8.Visible = xlSheetVisible
Planilha9.Visible = xlSheetVisible
Sheets("MENU_SISTEMAS_ADM").Select
Hide
End If
End If
End If
End Sub