Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Erro na Caixa de Combinação

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
LuizTSantos
Acabou de chegar
Acabou de chegar
Mensagens: 1
Registrado em: Ter Jan 05, 2021 2:46 pm

Erro na Caixa de Combinação

Mensagem por LuizTSantos »

Bom dia turma,

Estou montando um formulário de cadastro no VBA, porém do nada todas as minhas informações que estavam nas caixas de combinações sumiram, sou novo em VBA, peço a ajuda de vocês, vou deixar abaixo todas as linhas para verificarem onde está o erro e me ajudarem.

Código: Selecionar todos

Option Explicit
Global bloqueado As Boolean

Sub inserir()
    bloqueado = True
    Dim tabela As ListObject
    Dim n As Integer, id As Integer
    Set tabela = Planilha1.ListObjects(1)
    id = Range("ID").Value

    n = tabela.Range.Rows.Count
    tabela.Range(n, 1).Value = id
    tabela.Range(n, 2).Value = Userform1.txtnome.Value
    tabela.Range(n, 3).Value = Userform1.txtcpf.Value
    tabela.Range(n, 4).Value = Userform1.cbborg.Value
    tabela.Range(n, 5).Value = Userform1.cbbestado.Value
    tabela.Range(n, 6).Value = Userform1.cbbsexo.Value
    tabela.Range(n, 7).Value = Userform1.txtnascimento.Value
    tabela.Range(n, 8).Value = Userform1.txtrg.Value
    tabela.Range(n, 9).Value = Userform1.txtorg.Value
    tabela.Range(n, 10).Value = Userform1.txtufrg.Value
    tabela.Range(n, 11).Value = Userform1.txtdataemissao.Value
    tabela.Range(n, 12).Value = Userform1.txtnaturalidade.Value
    tabela.Range(n, 13).Value = Userform1.txtufnatu.Value
    tabela.Range(n, 14).Value = Userform1.txtnomepai.Value
    tabela.Range(n, 15).Value = Userform1.txtnomemae.Value
    tabela.Range(n, 16).Value = Userform1.txtendereco.Value
    tabela.Range(n, 17).Value = Userform1.txtcomplemento.Value
    tabela.Range(n, 18).Value = Userform1.txtcidade.Value
    tabela.Range(n, 19).Value = Userform1.txtbairro.Value
    tabela.Range(n, 20).Value = Userform1.txtcep.Value
    tabela.Range(n, 21).Value = Userform1.txtespecie.Value
    tabela.Range(n, 22).Value = Userform1.txtufmat.Value
    tabela.Range(n, 23).Value = Userform1.txtrenda.Value
    tabela.Range(n, 24).Value = Userform1.txttelresid.Value
    tabela.Range(n, 25).Value = Userform1.txtcel.Value
    tabela.Range(n, 26).Value = Userform1.txtbanco.Value
    tabela.Range(n, 27).Value = Userform1.txtagencia.Value
    tabela.Range(n, 28).Value = Userform1.txtcc.Value
    tabela.Range(n, 29).Value = Userform1.txttipo.Value
    tabela.Range(n, 30).Value = Userform1.txttipodeop.Value
    tabela.Range(n, 31).Value = Userform1.txtvalorb.Value
    tabela.Range(n, 32).Value = Userform1.txtvalorl.Value
    tabela.Range(n, 33).Value = Userform1.txtqtde.Value
    tabela.Range(n, 34).Value = Userform1.txtvalorp.Value
    tabela.Range(n, 35).Value = Userform1.txtprimeiro.Value


    Userform1.ListBox1.RowSource = ""
    tabela.ListRows.Add
    Range("ID").Value = id + 1
    Call Atualizar_Listbox
    Call LimparCampos
    MsgBox "Cadastrado Com Sucesso!", vbInformation, "Informação"
    bloqueado = False

End Sub

Sub Editar()

    bloqueado = True

    Dim tabela As ListObject
    Dim n As Integer, l As Integer
    Set tabela = Planilha1.ListObjects(1)

    n = Userform1.ListBox1.Value
    l = tabela.Range.Columns().Find(n, , , xlWhole).Row
    tabela.Range(l, 2).Value = Userform1.txtnome.Value
    tabela.Range(l, 3).Value = Userform1.txtcpf.Value
    tabela.Range(l, 4).Value = Userform1.cbborg.Value
    tabela.Range(l, 5).Value = Userform1.cbbestado.Value
    tabela.Range(l, 6).Value = Userform1.cbbsexo.Value
    tabela.Range(l, 7).Value = Userform1.txtnascimento.Value
    tabela.Range(l, 8).Value = Userform1.txtrg.Value
    tabela.Range(l, 9).Value = Userform1.txtorg.Value
    tabela.Range(l, 10).Value = Userform1.txtufrg.Value
    tabela.Range(l, 11).Value = Userform1.txtdataemissao.Value
    tabela.Range(l, 12).Value = Userform1.txtnaturalidade.Value
    tabela.Range(l, 13).Value = Userform1.txtufnatu.Value
    tabela.Range(l, 14).Value = Userform1.txtnomepai.Value
    tabela.Range(l, 15).Value = Userform1.txtnomemae.Value
    tabela.Range(l, 16).Value = Userform1.txtendereco.Value
    tabela.Range(l, 17).Value = Userform1.txtcomplemento.Value
    tabela.Range(l, 18).Value = Userform1.txtcidade.Value
    tabela.Range(l, 19).Value = Userform1.txtbairro.Value
    tabela.Range(l, 20).Value = Userform1.txtcep.Value
    tabela.Range(l, 21).Value = Userform1.txtespecie.Value
    tabela.Range(l, 22).Value = Userform1.txtufmat.Value
    tabela.Range(l, 23).Value = Userform1.txtrenda.Value
    tabela.Range(l, 24).Value = Userform1.txttelresid.Value
    tabela.Range(l, 25).Value = Userform1.txtcel.Value
    tabela.Range(l, 26).Value = Userform1.txtbanco.Value
    tabela.Range(l, 27).Value = Userform1.txtagencia.Value
    tabela.Range(l, 28).Value = Userform1.txtcc.Value
    tabela.Range(l, 29).Value = Userform1.txttipo.Value
    tabela.Range(l, 30).Value = Userform1.txttipodeop.Value
    tabela.Range(l, 31).Value = Userform1.txtvalorb.Value
    tabela.Range(l, 32).Value = Userform1.txtvalorl.Value
    tabela.Range(l, 33).Value = Userform1.txtqtde.Value
    tabela.Range(l, 34).Value = Userform1.txtvalorp.Value
    tabela.Range(l, 35).Value = Userform1.txtprimeiro.Value

    Call Atualizar_Listbox
    Call LimparCampos
    MsgBox "O Registro Foi Atualizado"

    bloqueado = False
End Sub

Sub Atualizar_Listbox()
    bloqueado = True
    Dim tabela As ListObject
    Set tabela = Planilha1.ListObjects(1)

    Userform1.ListBox1.RowSource = tabela.DataBodyRange.Address(, , , True)
    bloqueado = False
End Sub

Sub Deletar()


    bloqueado = True

    Dim tabela As ListObject
    Dim n As Integer, l As Integer
    Set tabela = Planilha1.ListObjects(1)

    n = Userform1.ListBox1.Value
    l = tabela.Range.Columns().Find(n, , , xlWhole).Row

    Userform1.ListBox1.RowSource = ""
    tabela.Range.Rows(l).Delete

    Call Atualizar_Listbox
    Call LimparCampos
    MsgBox "O Registro Foi Deletado"

    bloqueado = False


End Sub

Sub LimparCampos()
    Userform1.txtnome.Value = ""
    Userform1.txtcpf.Value = ""
    Userform1.cbborg.Value = ""
    Userform1.cbbestado.Value = ""
    Userform1.cbbsexo.Value = ""
    Userform1.txtemail.Value = ""
    Userform1.txtrg.Value = ""
    Userform1.txtorg.Value = ""
    Userform1.txtufrg.Value = ""
    Userform1.txtdataemissao.Value = ""
    Userform1.txtnaturalidade.Value = ""
    Userform1.txtufnatu.Value = ""
    Userform1.txtnomepai.Value = ""
    Userform1.txtnomemae.Value = ""
    Userform1.txtendereco.Value = ""
    Userform1.txtcomplemento.Value = ""
    Userform1.txtbairro.Value = ""
    Userform1.txtcep.Value = ""
    Userform1.txtmatricula.Value = ""
    Userform1.txtespecie.Value = ""
    Userform1.txtufmat.Value = ""
    Userform1.txtrenda.Value = ""
    Userform1.txttelresid.Value = ""
    Userform1.txtcel.Value = ""
    Userform1.txtbanco.Value = ""
    Userform1.txtagencia.Value = ""
    Userform1.txtcc.Value = ""
    Userform1.txttipo.Value = ""
    Userform1.txttipodeop.Value = ""
    Userform1.txtvalorb.Value = ""
    Userform1.txtvalorl.Value = ""
    Userform1.txtqtde.Value = ""
    Userform1.txtvalorp.Value = ""
    Userform1.txtprimeiro.Value = ""


End Sub

Sub Exibir()

    Userform1.Show

End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder