VBA doubt - Runtime error '91'

Asked

Viewed 1,441 times

2

'Procedimento para o Comando Entrar
Sub Entrar()

 'converte texto usuario para minusculo - formando um padrao
    frmLogin.txtUsuario = LCase(frmLogin.txtUsuario)

' Primeira parte - Verifica os campos vazios
If frmLogin.txtUsuario = "" Then
    MsgBox "Entre com o nome do Usuário", vbInformation, "USUÁRIO"
    Exit Sub
End If

If frmLogin.txtSenha = "" Then
    MsgBox "Entre com a senha do Usuário", vcInformation, "SENHA"
    Exit Sub
End If

' Segunda parte - verifica se é administrador e se for entra na planilha
If frmLogin.txtUsuario = "admin" And frmLogin.txtSenha = "admin" Then
    MsgBox "Bem Vindo Administrador.", vbOKOnly, "ACESSO LIBERADO"
    gravarRelatório
    LimparfrmLogin
    Unload frmLogin
    Application.Visible = True
    Sheets("USUÁRIO").Visible = xlSheetVisible
    Sheets("REL_ACESSO").Visible = xlSheetVisible
    Sheets("CONDIÇÃO.H.EXTRA").Visible = xlSheetVisible
    Sheets("UTIL.CONTROL.PONTO").Visible = xlSheetVisible
    Sheets("EMPREGADO.TESTE1").Select

    Exit Sub
End If

' Terceira parte - verifica se o usuário e senha estão no banco de dados
linha = 2
Usuario = frmLogin.txtUsuario
Senha = frmLogin.txtSenha

Do Until Sheets("USUÁRIO").Cells(linha, 1) = ""
If Sheets("USUÁRIO").Cells(linha, 1) = Usuario And Sheets("USUÁRIO").Cells(linha, 2) = Senha Then
    MsgBox "Bem Vindo " & Usuario, vbOKOnly, "ACESSO LIBERADO"
    gravarRelatório
    LimparfrmLogin
    Unload frmLogin
    Application.Visible = True
    Sheets("USUÁRIO").Visible = xlSheetVeryHidden
    Sheets("REL_ACESSO").Visible = xlSheetVeryHidden
    Sheets("CONDIÇÃO.H.EXTRA").Visible = xlSheetVeryHidden
    Sheets("UTIL.CONTROL.PONTO").Visible = xlSheetVeryHidden
    Sheets("EMPREGADO.TESTE1").Select
    Exit Sub
End If
linha = linha + 1
Loop

    MsgBox "Usuário ou Senha Inválidos", vbCritical, "ACESSO NEGADO"
    LimparfrmLogin
    frmLogin.txtUsuario.SetFocus
    Exit Sub
End Sub

No need to enter another code yet. Who can help and need more information.

Thanks in advance!

  • 1

    What’s the question? Where does the problem occur? In addition to posting the code, it is important you explain how the problem occurs.

  • Ricardo, welcome to Soft. Go to Ajuda and take the Tour, to make better use of the resources here, and see how to deal with the questions and answers. Try to be clear in your questions.

  • Hi. Welcome to Sopt. What colleagues mean is that it’s not enough just to put the code, because that way someone interested in helping you needs to copy it to put it on a spreadsheet and try to test it. Or else carefully analyze line by line to try to find where the error is. How you already know where the mistake is, please click [Edit] and add this information (the line where it occurs) to the question. And, do not forget: do the [tour] and read mainly [Ask].

  • Hi Ricardo, what? Did the answer serve you or was it useful? Here in the community we mark (check below the arrows next to the answer) the answer when this occurs, and we can vote by triggering the answers and questions arrows as well. I await your feedback, because if you have not solved the problem, give us more information to help you. Do the tour if you have not done it yet, it is important!

1 answer

0

The mistake 91 of VBA is:

Variable Unassigned With block object or variable

This type of error does not indicate where the problem occurred, so it should be in routine Limperfrmlogin. Depending on what is in this routine the problem will occur.

To check this, create breakpoints and track with the keys F8 (step by step) or F5 (until you find another breakpoint).

  • I don’t think this is necessarily the problem, because it does Unload the form but immediately ends the sub with exit sub. Therefore, the loop does not continue.

  • Ok, I will edit, because the problem must be in this routine and this type of error does not point out where it occurred.

  • Who should point out where it occurred is the AP, in question (after all, Excel stops at the line where the error occurred). : ) Until he does, you’ll have to keep trying to guess where the error is potentially occurring. Maybe you’re right, but potentially you can waste your time.

  • Okay, I get it. There was another question as soon as I indicated the use of interrupt points and the problem was found, I think that’s the case here.

  • Leo, your response effectively unresponsive to the question, because you say that maybe it is in the other routine that the AP did not post the code. In fact, we do not know yet where the error is. That is why I insist that information is lacking and we should wait. For you not to risk taking negativity, I would suggest commenting rather than answering. That is, remove this answer and answer again (in a more concrete and concrete way) after the AP update the question. :)

  • Okay, since the question is "open", I believe that what I indicated is the "solution" (as it served to another, I think it is the same case, not attentive to the interruption points), since he asks for "help" and is not specific in the question. There is no way to be precise without the rest of the code. I will wait.. for now..

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.