Notifications
Clear all

ERRO EM TEMPO DE EXECUÇÃO 91

9 Posts
3 Usuários
0 Reactions
1,723 Visualizações
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Boa tarde pessoal,
Criei um sisteminha em vba excel, porem está aparecendo um erro no código, e não estou encontrando, gostaria muito de pedir a ajuda de vcs.
Ocorre que quando eu abro o form, o código para deixar inativos e bloqueados todos os campos, não funciona. E quando clico no botão cancelar, ocorre o erro 91.

Obs.: meu form tem um multipage com 4 páginas(Page).

O código é seguinte:

Option Explicit

'SEÇÃO 1

Const colCPF As Integer = 1
Const colCNPJ1 As Integer = 2
Const colNOMEEMPRESA As Integer = 3
Const colCNAE As Integer = 4
Const colNOMETRAB As Integer = 5
Const colBRPDH As Integer = 6
Const colNIT1 As Integer = 7
Const colDTNASC As Integer = 8
Const colSEXO As Integer = 9
Const colCTPSN As Integer = 10
Const colCTPSS As Integer = 11
Const colCTPSUF As Integer = 12
Const colDTADM As Integer = 13
Const colREGIME As Integer = 14
Const colDTREGISTRO1 As Integer = 15
Const colNCAT1 As Integer = 16
Const colDTREGISTRO2 As Integer = 17
Const colNCAT2 As Integer = 18
Const colDTREGISTRO3 As Integer = 19
Const colNCAT3 As Integer = 20
Const colPERIODOLOT As Integer = 21
Const colCNPJ_CEI As Integer = 22
Const colSETOR As Integer = 23
Const colCARGO As Integer = 24
Const colFUNCAO As Integer = 25
Const colCBO As Integer = 26
Const colGFIP As Integer = 27
Const colDTINI5 As Integer = 28
Const colDTFIM5 As Integer = 29
Const colDESCRATIV1 As Integer = 30
Const colDTINI6 As Integer = 31
Const colDTFIM6 As Integer = 32
Const colDESCRATIV2 As Integer = 33
Const colDTINI7 As Integer = 34
Const colDTFIM7 As Integer = 35
Const colDESCRATIV3 As Integer = 36
'SEÇÃO 2
Const colDTINI1 As Integer = 37
Const colDTFIM1 As Integer = 38
Const colCBOTIPO1 As Integer = 39
Const colFATRISCO1 As Integer = 40
Const colIC1 As Integer = 41
Const colTECUTIL1 As Integer = 42
Const colEPC1 As Integer = 43
Const colEPI1 As Integer = 44
Const colCAEPI1 As Integer = 45

Const colDTINI2 As Integer = 46
Const colDTFIM2 As Integer = 47
Const colCBOTIPO2 As Integer = 48
Const colFATRISCO2 As Integer = 49
Const colIC2 As Integer = 50
Const colTECUTIL2 As Integer = 51
Const colEPC2 As Integer = 52
Const colEPI2 As Integer = 53
Const colCAEPI2 As Integer = 54


Const colDTINI3 As Integer = 55
Const colDTFIM3 As Integer = 56
Const colCBOTIPO3 As Integer = 57
Const colFATRISCO3 As Integer = 58
Const colIC3 As Integer = 59
Const colTECUTIL3 As Integer = 60
Const colEPC3 As Integer = 61
Const colEPI3 As Integer = 62
Const colCAEPI3 As Integer = 63

Const colDTINI4 As Integer = 64
Const colDTFIM4 As Integer = 65
Const colNITRESP As Integer = 66
Const colREGCONSCLASS As Integer = 67
Const colNOMEPROFLEG As Integer = 68

'SEÇÃO 4
Const colDTEMISS As Integer = 69
Const colNIT2 As Integer = 70
Const colNOMEREPRES As Integer = 71

Const indiceMinimo As Byte = 2
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643

Private wsCadastro As Worksheet
Private indiceRegistro As Long

Private Sub bntcancelar2_Click()
    btnOK.Enabled = False
    btnCancelar.Enabled = False
    Call DesabilitaControles
    Call CarregaDadosInicial
    Call HabilitaBotoesAlteracao
    Me.MultiPage1.Page1.txtCPF.SetFocus
End Sub

Private Sub btnCancelar_Click()
    btnOK.Enabled = False
    btnCancelar.Enabled = False
    Call DesabilitaControles
    Call CarregaDadosInicial
    Call HabilitaBotoesAlteracao
    Me.MultiPage1.Page1.txtCPF.SetFocus
End Sub

Private Sub btnCancelar1_Click()
    btnOK.Enabled = False
    btnCancelar.Enabled = False
    Call DesabilitaControles
    Call CarregaDadosInicial
    Call HabilitaBotoesAlteracao
    Me.MultiPage1.Page1.txtCPF.SetFocus
End Sub

Private Sub btnOK_Click()
    Dim proximoId As Long

    'Altera
    If optAlterar.Value Then
        Call SalvaRegistro(CLng(txtCPF.Text), indiceRegistro)
        MsgBox ("Registro salvo com sucesso")
    End If
    
    
    'Novo
    If optNovo.Value Then
        proximoId = PegaProximoId
        'pega a próxima linha
        Dim proximoIndice As Long
        proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
        Call SalvaRegistro(proximoId, proximoIndice)
        txtCPF = proximoId
        MsgBox ("Registro salvo com sucesso")
    End If
    
    
    'Excluir
    If optExcluir.Value Then
        Dim result As VbMsgBoxResult
        result = MsgBox("Deseja excluir o registro nº " & txtCPF.Text & " ?", vbYesNo, "Confirmação")

        If result = vbYes Then
            wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCPF), wsCadastro.Cells(indiceRegistro, colCPF)).EntireRow.Delete
            Call CarregaDadosInicial
            MsgBox ("Registro excluído com sucesso")
        End If
    End If

    Call HabilitaBotoesAlteracao
    Call DesabilitaControles

End Sub

Private Sub btnPesquisar_Click()
    frmPesquisa.Show
End Sub

Private Sub cbnEncerrar1_Click()
 Unload Me
End Sub

Private Sub cbnEncerrar2_Click()
Unload Me
End Sub

Private Sub cbnEncerrar3_Click()
Unload Me
End Sub
'bloqueia o botão X fechar do form
Private Sub frm_cadastro_QueryClose(Cancel As Integer, CloseMode As Integer)
     
    If CloseMode = 0 Then
        Cancel = True
        
        MsgBox ("Desculpe, use o botão [Sair]"), vbCritical, "Acesso negado"
        
    End If
     
End Sub

Private Sub optAlterar_Click()
    If txtCPF.Text <> vbNullString And txtCPF.Text <> "" Then
        Call HabilitaControles
        Call DesabilitaBotoesAlteracao
        'dá o foco ao primeiro controle de dados
        txt_cnpj1.SetFocus
    Else
        MsgBox ("Não há registro a ser alterado")
    End If
End Sub

Private Sub optExcluir_Click()
    If txtCPF.Text <> vbNullString And txtCPF.Text <> "" Then
        Call DesabilitaBotoesAlteracao
        MsgBox ("Modo de exclusão. Confira os dados do registro antes de excluí-lo")
    Else
        MsgBox ("Não há registro a ser excluído")
    End If
End Sub

Private Sub optNovo_Click()
    Call LimpaControles
    Call HabilitaControles
    Call DesabilitaBotoesAlteracao
    'dá o foco ao primeiro controle de dados
    Me.MultiPage1.Page1.txtCPF.SetFocus
End Sub

Private Sub frm_cadastro_Initialize()

       'TRATAMENTO DOS COMANDOS
    Set wsCadastro = ThisWorkbook.Worksheets("Cadastro")
    Call HabilitaBotoesAlteracao
    Call CarregaDadosInicial
    Call DesabilitaControles

    'ABRE FORM MAXIMIZADO E CENTRALIZADO
    ' ?

    'SELECIONADO O CAMPO CPF AO ABRI O FORM
    Me.MultiPage1.Page1.txtCPF.SetFocus
End Sub

Private Sub CarregaDadosInicial()
    indiceRegistro = 2
    Call CarregaRegistro
End Sub
Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
    With wsCadastro
            
        If Not IsEmpty(.Cells(indiceRegistro, colCPF)) Then   '<<<<O ERRO INDICA ESTA LINHA (msg de erro: A variável do objeto ou a variável do bloco 'With' não foi definida)

'''Obs.: caso o cód não funcionar, tentar chamar o registro usando no início da linha isso:
' Me.MultiPage1.nomedocampotxtdoform . Text = .Cells(indiceRegistro, colCPF).Value
'caso tenha que chamar para outra página é mudar Multipage1 para Multipage2 e assim por diante.


           Me.txtCPF.Text = .Cells(indiceRegistro, colCPF).Value '1
           Me.txt_cnpj1.Text = .Cells(indiceRegistro, colCNPJ1).Value '2
           Me.txt_nomeempresa.Text = .Cells(indiceRegistro, colNOMEEMPRESA).Value '3
           Me.txt_cnae.Text = .Cells(indiceRegistro, colCNAE).Value '4
           Me.txt_nometrab.Text = .Cells(indiceRegistro, colNOMETRAB).Value '5
           Me.txt_br_pdh.Text = .Cells(indiceRegistro, colBRPDH).Value '6
           Me.txt_nit.Text = .Cells(indiceRegistro, colNIT1).Value '7
           Me.txt_dtnasc.Text = .Cells(indiceRegistro, colDTNASC).Value '8
           Me.cbo_sexo.Text = .Cells(indiceRegistro, colSEXO).Value '9
           Me.txt_ctpsN.Text = .Cells(indiceRegistro, colCTPSN).Value '10
           Me.txt_ctpsS.Text = .Cells(indiceRegistro, colCTPSS).Value '11
           Me.txt_ctpsUF.Text = .Cells(indiceRegistro, colCTPSUF).Value '12
           Me.txt_dtAdmissao.Text = .Cells(indiceRegistro, colDTADM).Value '13
           Me.txt_Regime.Text = .Cells(indiceRegistro, colREGIME).Value '14
           Me.txt_dtRegistro1.Text = .Cells(indiceRegistro, colDTREGISTRO1).Value '15
           Me.txt_dtRegistro2.Text = .Cells(indiceRegistro, colDTREGISTRO2).Value '17
           Me.txt_dtRegistro2.Text = .Cells(indiceRegistro, colDTREGISTRO2).Value '18
           Me.txt_NCAT2.Text = .Cells(indiceRegistro, colNCAT2).Value '19
           Me.txt_dtRegistro3.Text = .Cells(indiceRegistro, colDTREGISTRO3).Value '19
           Me.txt_NCAT3.Text = .Cells(indiceRegistro, colNCAT3).Value '20
           Me.txt_periodoLOT.Text = .Cells(indiceRegistro, colPERIODOLOT).Value '21
           Me.txt_CNPJ_CEI.Text = .Cells(indiceRegistro, colCNPJ_CEI).Value '22
           Me.txt_setor.Text = .Cells(indiceRegistro, colSETOR).Value '23
           Me.txt_cargo.Text = .Cells(indiceRegistro, colCARGO).Value '24
           Me.txt_funcao.Text = .Cells(indiceRegistro, colFUNCAO).Value '25
           Me.txt_CBO.Text = .Cells(indiceRegistro, colCBO).Value1 '26
           Me.txt_codGFIP.Text = .Cells(indiceRegistro, colGFIP).Value '27
           Me.textDataIni5.Text = .Cells(indiceRegistro, colDTINI5).Value '28
           Me.textDataFin5.Text = .Cells(indiceRegistro, colDTFIM5).Value '29
           Me.txt_descrAtiv_1.Text = .Cells(indiceRegistro, colDESCRATIV1).Value '30
           Me.textDataIni6.Text = .Cells(indiceRegistro, colDTINI6).Value '31
           Me.textDataFin6.Text = .Cells(indiceRegistro, colDTFIM6).Value '32
           Me.txt_descrAtiv_2.Text = .Cells(indiceRegistro, colDESCRATIV2).Value '33
           Me.textDataIni7.Text = .Cells(indiceRegistro, colDTINI7).Value '34
           Me.textDataFin7.Text = .Cells(indiceRegistro, colDTFIM7).Value '35
           Me.txt_descrAtiv_3.Text = .Cells(indiceRegistro, colDESCRATIV3).Value '36
'SEÇÃO
           Me.textDataIni1.Text = .Cells(indiceRegistro, colDTINI1).Value '37
           Me.textDataFin1.Text = .Cells(indiceRegistro, colDTFIM1).Value '38
           Me.cbo_tipo1.Text = .Cells(indiceRegistro, colCBOTIPO1).Value '39
           Me.txt_FatRisco1.Text = .Cells(indiceRegistro, colFATRISCO1).Value '40
           Me.txt_I_C1.Text = .Cells(indiceRegistro, colIC1).Value '41
           Me.txt_tecUtil1.Text = .Cells(indiceRegistro, colTECUTIL1).Value '42
           Me.cbo_ECP1.Text = .Cells(indiceRegistro, colEPC1).Value '43
           Me.cbo_EPI1.Text = .Cells(indiceRegistro, colEPI1).Value '44
           Me.txt_CAEPI1.Text = .Cells(indiceRegistro, colCAEPI1).Value '45
           Me.textDataIni2.Text = .Cells(indiceRegistro, colDTINI2).Value '46
           Me.textDataFin2.Text = .Cells(indiceRegistro, colDTFIM2).Value '47
           Me.cbo_tipo2.Text = .Cells(indiceRegistro, colCBOTIPO2).Value '48
           Me.txt_FatRisco2.Text = .Cells(indiceRegistro, colFATRISCO2).Value '49
           Me.txt_I_C2.Text = .Cells(indiceRegistro, colIC2).Value '50
           Me.txt_tecUtil2.Text = .Cells(indiceRegistro, colTECUTIL2).Value '51
           Me.cbo_ECP2.Text = .Cells(indiceRegistro, colEPC2).Value '52
           Me.cbo_EPI2.Text = .Cells(indiceRegistro, colEPI2).Value '53
           Me.txt_CAEPI2.Text = .Cells(indiceRegistro, colCAEPI2).Value '54
           Me.textDataIni3.Text = .Cells(indiceRegistro, colDTINI3).Value '55
           Me.textDataFin3.Text = .Cells(indiceRegistro, colDTFIM3).Value '56
           Me.cbo_tipo3.Text = .Cells(indiceRegistro, colCBOTIPO3).Value '57
           Me.txt_FatRisco3.Text = .Cells(indiceRegistro, colFATRISCO3).Value '58

           Me.txt_I_C3.Text = .Cells(indiceRegistro, colIC3).Value '59
           Me.txt_tecUtil3.Text = .Cells(indiceRegistro, colTECUTIL3).Value '60
           Me.cbo_ECP3.Text = .Cells(indiceRegistro, colEPC3).Value '61
           Me.cbo_EPI3.Text = .Cells(indiceRegistro, colEPI3).Value '62
           Me.txt_CAEPI3.Text = .Cells(indiceRegistro, colCAEPI3).Value '63
           
           Me.textDataIni4.Text = .Cells(indiceRegistro, colDTINI4).Value '64
           Me.textDataFin4.Text = .Cells(indiceRegistro, colDTFIM4).Value '65
           Me.txt_NITresp.Value.Text = .Cells(indiceRegistro, colNITRESP).Value '66
           Me.txt_reg_cons_class.Value.Text = .Cells(indiceRegistro, colREGCONSCLASS).Value '67
           Me.txt_nome_prof_Leg_Hab.Value.Text = .Cells(indiceRegistro, colNOMEPROFLEG).Value '68

'SEÇÃO 4
           Me.textDataEmiss.Text = .Cells(indiceRegistro, colDTEMISS).Value '69
           Me.txt_NITrepresentante.Text = .Cells(indiceRegistro, colNIT2).Value '70
           Me.txt_nomerepresentante.Text = .Cells(indiceRegistro, colNOMEREPRES).Value '71

     End If
    End With

   ' Call AtualizaRegistroCorrente
End Sub

Public Sub CarregaRegistroPorIndice(ByVal indice As Long)
'carrega os dados do registro baseado no índice
    indiceRegistro = indice

    Call CarregaRegistro
End Sub

Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
    With wsCadastro
        
        .Cells(indice, colCPF).Value = id
    '     .Cells(indiceRegistro, colCPF).Value = Me.txtCPF.Text'1
          .Cells(indiceRegistro, colCNPJ1).Value = Me.txt_cnpj1.Text '2
          .Cells(indiceRegistro, colNOMEEMPRESA).Value = Me.txt_nomeempresa.Text '3
          .Cells(indiceRegistro, colCNAE).Value = Me.txt_cnae.Text '4
          .Cells(indiceRegistro, colNOMETRAB).Value = Me.txt_nometrab.Text '5
          .Cells(indiceRegistro, colBRPDH).Value = Me.txt_br_pdh.Text '6
          .Cells(indiceRegistro, colNIT1).Value = Me.txt_nit.Text '7
          .Cells(indiceRegistro, colDTNASC).Value = Me.txt_dtnasc.Text '8
          .Cells(indiceRegistro, colSEXO).Value = Me.cbo_sexo.Text '9
          .Cells(indiceRegistro, colCTPSN).Value = Me.txt_ctpsN.Text '10
          .Cells(indiceRegistro, colCTPSS).Value = Me.txt_ctpsS.Text '11
          .Cells(indiceRegistro, colCTPSUF).Value = Me.txt_ctpsUF.Text '12
          .Cells(indiceRegistro, colDTADM).Value = Me.txt_dtAdmissao.Text '13
          .Cells(indiceRegistro, colREGIME).Value = Me.txt_Regime.Text '14
          .Cells(indiceRegistro, colDTREGISTRO1).Value = Me.txt_dtRegistro1.Text '15
          .Cells(indiceRegistro, colNCAT1).Value = Me.txt_NCAT1.Text '16
          .Cells(indiceRegistro, colDTREGISTRO2).Value = Me.txt_dtRegistro2.Text '17
          .Cells(indiceRegistro, colNCAT2).Value = Me.txt_NCAT2.Text '18
          .Cells(indiceRegistro, colDTREGISTRO3).Value = Me.txt_dtRegistro3.Text '19
          .Cells(indiceRegistro, colNCAT3).Value = Me.txt_NCAT3.Text '20
          .Cells(indiceRegistro, colPERIODOLOT).Value = Me.txt_periodoLOT.Text '21
          .Cells(indiceRegistro, colCNPJ_CEI).Value = Me.txt_CNPJ_CEI.Text '22
          .Cells(indiceRegistro, colSETOR).Value = Me.txt_setor.Text '23
          .Cells(indiceRegistro, colCARGO).Value = Me.txt_cargo.Text '24
          .Cells(indiceRegistro, colFUNCAO).Value = Me.txt_funcao.Text '25
          .Cells(indiceRegistro, colCBO).Value = Me.txt_CBO.Text '26
          .Cells(indiceRegistro, colGFIP).Value = Me.txt_codGFIP.Text '27
          .Cells(indiceRegistro, colDTINI5).Value = Me.textDataIni5.Text '28
          .Cells(indiceRegistro, colDTFIM5).Value = Me.textDataFin5.Text '29
          .Cells(indiceRegistro, colDESCRATIV1).Value = Me.txt_descrAtiv_1.Text '30
          .Cells(indiceRegistro, colDTINI6).Value = Me.textDataIni6.Text '31
          .Cells(indiceRegistro, colDTFIM6).Value = Me.textDataFin6.Text '32
          .Cells(indiceRegistro, colDESCRATIV2).Value = Me.txt_descrAtiv_2.Text '33
          .Cells(indiceRegistro, colDTINI7).Value = Me.textDataIni7.Text '34
          .Cells(indiceRegistro, colDTFIM7).Value = Me.textDataFin7.Text '35
          .Cells(indiceRegistro, colDESCRATIV3).Value = Me.txt_descrAtiv_3.Text '36
'SEÇÃO 2
          .Cells(indiceRegistro, colDTINI1).Value = Me.textDataIni1.Text '37
          .Cells(indiceRegistro, colDTFIM1).Value = Me.textDataFin1.Text '38
          .Cells(indiceRegistro, colCBOTIPO1).Value = Me.cbo_tipo1.Text '39
          .Cells(indiceRegistro, colFATRISCO1).Value = Me.txt_FatRisco1.Text '40
          .Cells(indiceRegistro, colIC1).Value = Me.txt_I_C1.Text '41
          .Cells(indiceRegistro, colTECUTIL1).Value = Me.txt_tecUtil1.Text '42
          .Cells(indiceRegistro, colEPC1).Value = Me.cbo_ECP1.Text '43
          .Cells(indiceRegistro, colEPI1).Value = Me.cbo_EPI1.Text '44
          .Cells(indiceRegistro, colCAEPI1).Value = Me.txt_CAEPI1.Text '45
          .Cells(indiceRegistro, colDTINI2).Value = Me.textDataIni2.Text '46
          .Cells(indiceRegistro, colDTFIM2).Value = Me.textDataFin2.Text '47
          .Cells(indiceRegistro, colCBOTIPO2).Value = Me.cbo_tipo2.Text '48
          .Cells(indiceRegistro, colFATRISCO2).Value = Me.txt_FatRisco2.Text '49
          .Cells(indiceRegistro, colIC2).Value = Me.txt_I_C2.Text '50
          .Cells(indiceRegistro, colTECUTIL2).Value = Me.txt_tecUtil2.Text '51
          .Cells(indiceRegistro, colEPC2).Value = Me.cbo_ECP2.Text '52
          .Cells(indiceRegistro, colEPI2).Value = Me.cbo_EPI2.Text '53
          .Cells(indiceRegistro, colCAEPI2).Value = Me.txt_CAEPI2.Text '54
          .Cells(indiceRegistro, colDTINI3).Value = Me.textDataIni3.Text '55
          .Cells(indiceRegistro, colDTFIM3).Value = Me.textDataFin3.Text '56
          .Cells(indiceRegistro, colCBOTIPO3).Value = Me.cbo_tipo3.Text '57
          .Cells(indiceRegistro, colFATRISCO3).Value = Me.txt_FatRisco3.Text '58

          .Cells(indiceRegistro, colIC3).Value = Me.txt_I_C3.Text '59
          .Cells(indiceRegistro, colTECUTIL3).Value = Me.txt_tecUtil3.Text '60
          .Cells(indiceRegistro, colEPC3).Value = Me.cbo_ECP3.Text '61
          .Cells(indiceRegistro, colEPI3).Value = Me.cbo_EPI3.Text '62
          .Cells(indiceRegistro, colCAEPI3).Value = Me.txt_CAEPI3.Text '63
          
          .Cells(indiceRegistro, colDTINI4).Value = Me.textDataIni4.Text '64
          .Cells(indiceRegistro, colDTFIM4).Value = Me.textDataFin4.Text '65
          .Cells(indiceRegistro, colNITRESP).Value = Me.txt_NITresp.Text '66
          .Cells(indiceRegistro, colREGCONSCLASS).Value = Me.txt_reg_cons_class.Text '67
          .Cells(indiceRegistro, colNOMEPROFLEG).Value = Me.txt_nome_prof_Leg_Hab.Text '68
          
          
'SEÇÃO 4
          .Cells(indiceRegistro, colDTEMISS).Value = Me.textDataEmiss.Text '69
          .Cells(indiceRegistro, colNIT2).Value = Me.txt_NITrepresentante.Text '70
          .Cells(indiceRegistro, colNOMEREPRES).Value = Me.txt_nomerepresentante.Text '71

    End With

  '  Call AtualizaRegistroCorrente
End Sub


Private Function PegaProximoId() As Long
    Dim rangeIds As Range
    'pega o range que se refere a toda a coluna do código (id)
    Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colCPF), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCPF))
    PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function
Private Function PegaProximoId() As Long
    Dim rangeIds As Range
    'pega o range que se refere a toda a coluna do código (id)
    Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colCPF), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCPF))
    PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function

'Private Sub AtualizaRegistroCorrente()
  '  lblNavigator.Caption = indiceRegistro - 1 & " de " & wsCadastro.UsedRange.Rows.Count - 1
'    lblMensagem.Caption = ""
' End Sub

Private Sub LimpaControles()

Me.txtCPF.Text = ""
Me.txt_cnpj1.Text = ""
Me.txt_nomeempresa.Text = ""
Me.txt_cnae.Text = ""
Me.txt_nometrab.Text = ""
Me.txt_br_pdh.Text = ""
Me.txt_nit.Text = ""
Me.txt_dtnasc.Text = ""
Me.cbo_sexo.Text = ""
Me.txt_ctpsN.Text = ""
Me.txt_ctpsS.Text = ""
Me.txt_ctpsUF.Text = ""
Me.txt_dtAdmissao.Text = ""
Me.txt_Regime.Text = ""
Me.txt_dtRegistro1.Text = ""
Me.txt_NCAT1.Text = ""
Me.txt_dtRegistro2.Text = ""
Me.txt_NCAT2.Text = ""
Me.txt_dtRegistro3.Text = ""
Me.txt_NCAT3.Text = ""
Me.txt_periodoLOT.Text = ""
Me.txt_CNPJ_CEI.Text = ""
Me.txt_setor.Text = ""
Me.txt_cargo.Text = ""
Me.txt_funcao.Text = ""
Me.txt_CBO.Text = ""
Me.txt_codGFIP.Text = ""
Me.textDataIni5.Text = ""
Me.textDataFin5.Text = ""
Me.txt_descrAtiv_1.Text = ""
Me.textDataIni6.Text = ""
Me.textDataFin6.Text = ""
Me.txt_descrAtiv_2.Text = ""
Me.textDataIni7.Text = ""
Me.textDataFin7.Text = ""
Me.txt_descrAtiv_3.Text = ""
Me.textDataIni1.Text = ""
Me.textDataFin1.Text = ""
Me.textDataIni2.Text = ""
Me.textDataFin2.Text = ""
Me.textDataIni3.Text = ""
Me.textDataFin3.Text = ""
Me.cbo_tipo1.Text = ""
Me.cbo_tipo2.Text = ""
Me.cbo_tipo3.Text = ""
Me.txt_FatRisco1.Text = ""
Me.txt_FatRisco2.Text = ""
Me.txt_FatRisco3.Text = ""
Me.txt_I_C1.Text = ""
Me.txt_I_C2.Text = ""
Me.txt_I_C3.Text = ""
Me.txt_tecUtil1.Text = ""
Me.txt_tecUtil2.Text = ""
Me.txt_tecUtil3.Text = ""
Me.cbo_ECP1.Text = ""
Me.cbo_ECP2.Text = ""
Me.cbo_ECP3.Text = ""
Me.cbo_EPI1.Text = ""
Me.cbo_EPI2.Text = ""
Me.cbo_EPI3.Text = ""
Me.txt_CAEPI1.Text = ""
Me.txt_CAEPI2.Text = ""
Me.txt_CAEPI3.Text = ""

Me.textDataIni4.Text = ""
Me.textDataFin4.Text = ""
Me.txt_NITresp.Text = ""
Me.txt_reg_cons_class.Text = ""
Me.txt_nome_prof_Leg_Hab.Text = ""

Me.textDataEmiss.Text = ""
Me.txt_NITrepresentante.Text = ""
Me.txt_nomerepresentante.Text = ""
End Sub

Private Sub HabilitaControles()

Me.txtCPF.Locked = False
Me.txt_cnpj1.Locked = False
Me.txt_nomeempresa.Locked = False
Me.txt_cnae.Locked = False
Me.txt_nometrab.Locked = False
Me.txt_br_pdh.Locked = False
Me.txt_nit.Locked = False
Me.txt_dtnasc.Locked = False
Me.cbo_sexo.Locked = False
Me.txt_ctpsN.Locked = False
Me.txt_ctpsS.Locked = False
Me.txt_ctpsUF.Locked = False
Me.txt_dtAdmissao.Locked = False
Me.txt_Regime.Locked = False
Me.txt_dtRegistro1.Locked = False
Me.txt_NCAT1.Locked = False
Me.txt_dtRegistro2.Locked = False
Me.txt_NCAT2.Locked = False
Me.txt_dtRegistro3.Locked = False
Me.txt_NCAT3.Locked = False
Me.txt_periodoLOT.Locked = False
Me.txt_CNPJ_CEI.Locked = False
Me.txt_setor.Locked = False
Me.txt_cargo.Locked = False
Me.txt_funcao.Locked = False
Me.txt_CBO.Locked = False
Me.txt_codGFIP.Locked = False
Me.textDataIni5.Locked = False
Me.textDataFin5.Locked = False
Me.txt_descrAtiv_1.Locked = False
Me.textDataIni6.Locked = False
Me.textDataFin6.Locked = False
Me.txt_descrAtiv_2.Locked = False
Me.textDataIni7.Locked = False
Me.textDataFin7.Locked = False
Me.txt_descrAtiv_3.Locked = False
Me.textDataIni1.Locked = False
Me.textDataFin1.Locked = False
Me.textDataIni2.Locked = False
Me.textDataFin2.Locked = False
Me.textDataIni3.Locked = False
Me.textDataFin3.Locked = False
Me.cbo_tipo1.Locked = False
Me.cbo_tipo2.Locked = False
Me.cbo_tipo3.Locked = False
Me.txt_FatRisco1.Locked = False
Me.txt_FatRisco2.Locked = False
Me.txt_FatRisco3.Locked = False
Me.txt_I_C1.Locked = False
Me.txt_I_C2.Locked = False
Me.txt_I_C3.Locked = False
Me.txt_tecUtil1.Locked = False
Me.txt_tecUtil2.Locked = False
Me.txt_tecUtil3.Locked = False
Me.cbo_ECP1.Locked = False
Me.cbo_ECP2.Locked = False
Me.cbo_ECP3.Locked = False
Me.cbo_EPI1.Locked = False
Me.cbo_EPI2.Locked = False
Me.cbo_EPI3.Locked = False
Me.txt_CAEPI1.Locked = False
Me.txt_CAEPI2.Locked = False
Me.txt_CAEPI3.Locked = False

Me.textDataIni4.Locked = False
Me.textDataFin4.Locked = False
Me.txt_NITresp.Locked = False
Me.txt_reg_cons_class.Locked = False
Me.txt_nome_prof_Leg_Hab.Locked = False

Me.textDataEmiss.Locked = False
Me.txt_NITrepresentante.Locked = False
Me.txt_nomerepresentante.Locked = False


' ATIVA A COR DE FUNDO DO CAMPO DE TEXTO

Me.txtCPF.BackColor = corEnabledTextBox
Me.txt_cnpj1.BackColor = corEnabledTextBox
Me.txt_nomeempresa.BackColor = corEnabledTextBox
Me.txt_cnae.BackColor = corEnabledTextBox
Me.txt_nometrab.BackColor = corEnabledTextBox
Me.txt_br_pdh.BackColor = corEnabledTextBox
Me.txt_nit.BackColor = corEnabledTextBox
Me.txt_dtnasc.BackColor = corEnabledTextBox
Me.cbo_sexo.BackColor = corEnabledTextBox
Me.txt_ctpsN.BackColor = corEnabledTextBox
Me.txt_ctpsS.BackColor = corEnabledTextBox
Me.txt_ctpsUF.BackColor = corEnabledTextBox
Me.txt_dtAdmissao.BackColor = corEnabledTextBox
Me.txt_Regime.BackColor = corEnabledTextBox
Me.txt_dtRegistro1.BackColor = corEnabledTextBox
Me.txt_NCAT1.BackColor = corEnabledTextBox
Me.txt_dtRegistro2.BackColor = corEnabledTextBox
Me.txt_NCAT2.BackColor = corEnabledTextBox
Me.txt_dtRegistro3.BackColor = corEnabledTextBox
Me.txt_NCAT3.BackColor = corEnabledTextBox
Me.txt_periodoLOT.BackColor = corEnabledTextBox
Me.txt_CNPJ_CEI.BackColor = corEnabledTextBox
Me.txt_setor.BackColor = corEnabledTextBox
Me.txt_cargo.BackColor = corEnabledTextBox
Me.txt_funcao.BackColor = corEnabledTextBox
Me.txt_CBO.BackColor = corEnabledTextBox
Me.txt_codGFIP.BackColor = corEnabledTextBox
Me.textDataIni5.BackColor = corEnabledTextBox
Me.textDataFin5.BackColor = corEnabledTextBox
Me.txt_descrAtiv_1.BackColor = corEnabledTextBox
Me.textDataIni6.BackColor = corEnabledTextBox
Me.textDataFin6.BackColor = corEnabledTextBox
Me.txt_descrAtiv_2.BackColor = corEnabledTextBox
Me.textDataIni7.BackColor = corEnabledTextBox
Me.textDataFin7.BackColor = corEnabledTextBox
Me.txt_descrAtiv_3.BackColor = corEnabledTextBox
Me.textDataIni1.BackColor = corEnabledTextBox
Me.textDataFin1.BackColor = corEnabledTextBox
Me.textDataIni2.BackColor = corEnabledTextBox
Me.textDataFin2.BackColor = corEnabledTextBox
Me.textDataIni3.BackColor = corEnabledTextBox
Me.textDataFin3.BackColor = corEnabledTextBox
Me.cbo_tipo1.BackColor = corEnabledTextBox
Me.cbo_tipo2.BackColor = corEnabledTextBox
Me.cbo_tipo3.BackColor = corEnabledTextBox
Me.txt_FatRisco1.BackColor = corEnabledTextBox
Me.txt_FatRisco2.BackColor = corEnabledTextBox
Me.txt_FatRisco3.BackColor = corEnabledTextBox
Me.txt_I_C1.BackColor = corEnabledTextBox
Me.txt_I_C2.BackColor = corEnabledTextBox
Me.txt_I_C3.BackColor = corEnabledTextBox
Me.txt_tecUtil1.BackColor = corEnabledTextBox
Me.txt_tecUtil2.BackColor = corEnabledTextBox
Me.txt_tecUtil3.BackColor = corEnabledTextBox
Me.cbo_ECP1.BackColor = corEnabledTextBox
Me.cbo_ECP2.BackColor = corEnabledTextBox
Me.cbo_ECP3.BackColor = corEnabledTextBox
Me.cbo_EPI1.BackColor = corEnabledTextBox
Me.cbo_EPI2.BackColor = corEnabledTextBox
Me.cbo_EPI3.BackColor = corEnabledTextBox
Me.txt_CAEPI1.BackColor = corEnabledTextBox
Me.txt_CAEPI2.BackColor = corEnabledTextBox
Me.txt_CAEPI3.BackColor = corEnabledTextBox
Me.textDataIni4.BackColor = corEnabledTextBox
Me.textDataFin4.BackColor = corEnabledTextBox
Me.txt_NITresp.BackColor = corEnabledTextBox
Me.txt_reg_cons_class.BackColor = corEnabledTextBox
Me.txt_nome_prof_Leg_Hab.BackColor = corEnabledTextBox

Me.textDataEmiss.BackColor = corEnabledTextBox
Me.txt_NITrepresentante.BackColor = corEnabledTextBox
Me.txt_nomerepresentante.BackColor = corEnabledTextBox
End Sub

Private Sub DesabilitaControles()

Me.txtCPF.Locked = True
Me.txt_cnpj1.Locked = True
Me.txt_nomeempresa.Locked = True
Me.txt_cnae.Locked = True
Me.txt_nometrab.Locked = True
Me.txt_br_pdh.Locked = True
Me.txt_nit.Locked = True
Me.txt_dtnasc.Locked = True
Me.cbo_sexo.Locked = True
Me.txt_ctpsN.Locked = True
Me.txt_ctpsS.Locked = True
Me.txt_ctpsUF.Locked = True
Me.txt_dtAdmissao.Locked = True
Me.txt_Regime.Locked = True
Me.txt_dtRegistro1.Locked = True
Me.txt_NCAT1.Locked = True
Me.txt_dtRegistro2.Locked = True
Me.txt_NCAT2.Locked = True
Me.txt_dtRegistro3.Locked = True
Me.txt_NCAT3.Locked = True
Me.txt_periodoLOT.Locked = True
Me.txt_CNPJ_CEI.Locked = True
Me.txt_setor.Locked = True
Me.txt_cargo.Locked = True
Me.txt_funcao.Locked = True
Me.txt_CBO.Locked = True
Me.txt_codGFIP.Locked = True
Me.textDataIni5.Locked = True
Me.textDataFin5.Locked = True
Me.txt_descrAtiv_1.Locked = True
Me.textDataIni6.Locked = True
Me.textDataFin6.Locked = True
Me.txt_descrAtiv_2.Locked = True
Me.textDataIni7.Locked = True
Me.textDataFin7.Locked = True
Me.txt_descrAtiv_3.Locked = True
Me.textDataIni1.Locked = True
Me.textDataFin1.Locked = True
Me.textDataIni2.Locked = True
Me.textDataFin2.Locked = True
Me.textDataIni3.Locked = True
Me.textDataFin3.Locked = True
Me.cbo_tipo1.Locked = True
Me.cbo_tipo2.Locked = True
Me.cbo_tipo3.Locked = True
Me.txt_FatRisco1.Locked = True
Me.txt_FatRisco2.Locked = True
Me.txt_FatRisco3.Locked = True
Me.txt_I_C1.Locked = True
Me.txt_I_C2.Locked = True
Me.txt_I_C3.Locked = True
Me.txt_tecUtil1.Locked = True
Me.txt_tecUtil2.Locked = True
Me.txt_tecUtil3.Locked = True
Me.cbo_ECP1.Locked = True
Me.cbo_ECP2.Locked = True
Me.cbo_ECP3.Locked = True
Me.cbo_EPI1.Locked = True
Me.cbo_EPI2.Locked = True
Me.cbo_EPI3.Locked = True
Me.txt_CAEPI1.Locked = True
Me.txt_CAEPI2.Locked = True
Me.txt_CAEPI3.Locked = True

Me.textDataIni4.Locked = True
Me.textDataFin4.Locked = True
Me.txt_NITresp.Locked = True
Me.txt_reg_cons_class.Locked = True
Me.txt_nome_prof_Leg_Hab.Locked = True

Me.textDataEmiss.Locked = True
Me.txt_NITrepresentante.Locked = True
Me.txt_nomerepresentante.Locked = True
 
' DESATIVA A COR DE FUNDO DO CAMPO DE TEXTO

Me.txtCPF.BackColor = corDisabledTextBox
Me.txt_cnpj1.BackColor = corDisabledTextBox
Me.txt_nomeempresa.BackColor = corDisabledTextBox
Me.txt_cnae.BackColor = corDisabledTextBox
Me.txt_nometrab.BackColor = corDisabledTextBox
Me.txt_br_pdh.BackColor = corDisabledTextBox
Me.txt_nit.BackColor = corDisabledTextBox
Me.txt_dtnasc.BackColor = corDisabledTextBox
Me.cbo_sexo.BackColor = corDisabledTextBox
Me.txt_ctpsN.BackColor = corDisabledTextBox
Me.txt_ctpsS.BackColor = corDisabledTextBox
Me.txt_ctpsUF.BackColor = corDisabledTextBox
Me.txt_dtAdmissao.BackColor = corDisabledTextBox
Me.txt_Regime.BackColor = corDisabledTextBox
Me.txt_dtRegistro1.BackColor = corDisabledTextBox
Me.txt_NCAT1.BackColor = corDisabledTextBox
Me.txt_dtRegistro2.BackColor = corDisabledTextBox
Me.txt_NCAT2.BackColor = corDisabledTextBox
Me.txt_dtRegistro3.BackColor = corDisabledTextBox
Me.txt_NCAT3.BackColor = corDisabledTextBox
Me.txt_periodoLOT.BackColor = corDisabledTextBox
Me.txt_CNPJ_CEI.BackColor = corDisabledTextBox
Me.txt_setor.BackColor = corDisabledTextBox
Me.txt_cargo.BackColor = corDisabledTextBox
Me.txt_funcao.BackColor = corDisabledTextBox
Me.txt_CBO.BackColor = corDisabledTextBox
Me.txt_codGFIP.BackColor = corDisabledTextBox
Me.textDataIni5.BackColor = corDisabledTextBox
Me.textDataFin5.BackColor = corDisabledTextBox
Me.txt_descrAtiv_1.BackColor = corDisabledTextBox
Me.textDataIni6.BackColor = corDisabledTextBox
Me.textDataFin6.BackColor = corDisabledTextBox
Me.txt_descrAtiv_2.BackColor = corDisabledTextBox
Me.textDataIni7.BackColor = corDisabledTextBox
Me.textDataFin7.BackColor = corDisabledTextBox
Me.txt_descrAtiv_3.BackColor = corDisabledTextBox
Me.textDataIni1.BackColor = corDisabledTextBox
Me.textDataFin1.BackColor = corDisabledTextBox
Me.textDataIni2.BackColor = corDisabledTextBox
Me.textDataFin2.BackColor = corDisabledTextBox
Me.textDataIni3.BackColor = corDisabledTextBox
Me.textDataFin3.BackColor = corDisabledTextBox
Me.cbo_tipo1.BackColor = corDisabledTextBox
Me.cbo_tipo2.BackColor = corDisabledTextBox
Me.cbo_tipo3.BackColor = corDisabledTextBox
Me.txt_FatRisco1.BackColor = corDisabledTextBox
Me.txt_FatRisco2.BackColor = corDisabledTextBox
Me.txt_FatRisco3.BackColor = corDisabledTextBox
Me.txt_I_C1.BackColor = corDisabledTextBox
Me.txt_I_C2.BackColor = corDisabledTextBox
Me.txt_I_C3.BackColor = corDisabledTextBox
Me.txt_tecUtil1.BackColor = corDisabledTextBox
Me.txt_tecUtil2.BackColor = corDisabledTextBox
Me.txt_tecUtil3.BackColor = corDisabledTextBox
Me.cbo_ECP1.BackColor = corDisabledTextBox
Me.cbo_ECP2.BackColor = corDisabledTextBox
Me.cbo_ECP3.BackColor = corDisabledTextBox
Me.cbo_EPI1.BackColor = corDisabledTextBox
Me.cbo_EPI2.BackColor = corDisabledTextBox
Me.cbo_EPI3.BackColor = corDisabledTextBox
Me.txt_CAEPI1.BackColor = corDisabledTextBox
Me.txt_CAEPI2.BackColor = corDisabledTextBox
Me.txt_CAEPI3.BackColor = corDisabledTextBox

Me.textDataIni4.BackColor = corDisabledTextBox
Me.textDataFin4.BackColor = corDisabledTextBox
Me.txt_NITresp.BackColor = corDisabledTextBox
Me.txt_reg_cons_class.BackColor = corDisabledTextBox
Me.txt_nome_prof_Leg_Hab.BackColor = corDisabledTextBox

Me.textDataEmiss.BackColor = corDisabledTextBox
Me.txt_NITrepresentante.BackColor = corDisabledTextBox
Me.txt_nomerepresentante.BackColor = corDisabledTextBox

End Sub

Private Sub HabilitaBotoesAlteracao()
'habilita os botões de alteração
    optAlterar.Enabled = True
    optExcluir.Enabled = True
    optNovo.Enabled = True
    btnPesquisar.Enabled = True
    btnOK.Enabled = False
    btnCancelar.Enabled = False
    btnCancelar1.Enabled = False
    bntcancelar2.Enabled = False
    
    'limpa os valores dos controles
    optAlterar.Value = False
    optExcluir.Value = False
    optNovo.Value = False

End Sub

Private Sub DesabilitaBotoesAlteracao()
'desabilita os botões de alteração
    optAlterar.Enabled = False
    optExcluir.Enabled = False
    optNovo.Enabled = False
    btnPesquisar.Enabled = False
    btnOK.Enabled = True
    btnCancelar.Enabled = True
     btnCancelar1.Enabled = True
    bntcancelar2.Enabled = True

End Sub

Public Function ProcuraIndiceRegistroPodId(ByVal id As Long) As Long
    Dim i As Long
    Dim retorno As Long
    Dim encontrado As Boolean

    i = indiceMinimo
    With wsCadastro
        Do While Not IsEmpty(.Cells(i, colCPF))
            If .Cells(i, colCPF).Value = id Then
                retorno = i
                encontrado = True
                Exit Do
            End If
            i = i + 1
        Loop
    End With

    'caso não encontre o registro, retorna -1
    If Not encontrado Then
        retorno = -1
    End If

    ProcuraIndiceRegistroPodId = i
End Function
 
Postado : 17/12/2015 12:55 pm
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

BrunoMotta,

Boa tarde!

Por gentileza, anexe seu arquivo aqui mesmo no fórum ou um arquivo exemplo compactado (porém com layout original dos seus dados) para que todos possam analisar, rodar e depurar seu código. Assim ficará mais fácil ajudar.

 
Postado : 17/12/2015 1:13 pm
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Wagner
Conforme solicitado, segue em anexo.

Perdoe-me se está uma bagunça o código...rsrsr, pois estou fazendo vários testes, estava pensando em organizar depois de testá-lo.

Desde já agradeço a ajuda.

 
Postado : 17/12/2015 3:34 pm
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Wagner desculpe

LOGIN: ADMIN
senha: admin

 
Postado : 18/12/2015 6:51 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

Ok.

Me diga como eu faço para que o erro aconteça por aqui. Qual o caminho, como devo executar para chegar ao erro.

Me informe também a senha do projeto VBA.

 
Postado : 18/12/2015 8:30 am
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Wagner consegui resolver o erro 91, mas para o meu azar, apareceu outro erro 424.

Para facilitar a ajuda, retirei todos os bloqueios do projeto. Ao abrir o projeto, basta você clicar no BOTÃO "PPP" para abri o form, logo aparecerá a msg de erro 424, dizendo que o objeto é obrigatório.

Na verdade eu percebi que este erro aparece, logo depois que eu crio o primeiro registro, aí...ao tentar utilizar os botões (próximo) e (último registro) da barra de navegação criada no form, aparece o erro, após depurar, e tentar abrir novamente o form, ele não abre sinalizando o erro 424.

A depuração inidica :
Public Sub AbreFormCadastro()
Cadastro.Show <<<<<<o erro está nessa linha, mas verifiquei e está tudo certinho, eu acho!!!! rsrsrs
End Sub

Vou anexar novamente o arquivo já desbloqueado ok!

 
Postado : 21/12/2015 8:27 am
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Obs.: quando eu excluo o registro criado, diretamente na planilha "Cadastro", e clico para abri o form no botão [PPP], ele abre normalmente. Estou quase deletando essa b... e criando outro projeto. kkkk

 
Postado : 21/12/2015 8:45 am
(@brunomotta)
Posts: 0
New Member
Topic starter
 

Oi meu amigo Wagner, vc conseguiu algo que possa solucionar essa?
A dois dias eu tinha um cabelo até que bacana, agora estou precisando de um implante capilar, pois perdi todos os meus cabelos, por causa desse código.

 
Postado : 22/12/2015 12:01 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Acostume-se ao entrar em modo de depuração, acompanhar a rotina com F8, assim irá percorrendo a rotina passo a passo.
Erro reportado deve-se ao fato de na Rotina CarregaRegistro() ao chegar na "linha" que carregatxt_NITresp (identificado com 66 no final da linha), a sintaxe do objeto esta errada
Esta: Me.txt_NITresp..Value.Text ....
Correto: Me.txt_NITresp.Text ...
Verifique as demais abaixo tambem.

 
Postado : 23/12/2015 7:48 am