- 20 Ago 2020 às 16:26
#58081
Prezados, boa tarde!
Pode ser que essa minha dúvida tenha sido respondida em algum outro tópico, mas como sou iniciante em VBA ainda não consegui rodar meu formulário devido a esse "Erro em tempo de execução '380' - Não foi possível definir a propriedade List. Valor de propriedade inválido." Sendo assim, venho buscar essa pequena ajuda com o conhecimento avançado de vocês.
Segue abaixo o meu código:
Private Sub ListBox_cliente_Click()
Me.Text_idcliente.Text = ""
Me.Text_nome.Text = ""
Me.Text_colaborador.Text = ""
Me.Text_siape.Text = ""
Me.Text_cpf.Text = ""
Me.Text_celular.Text = ""
Me.Text_ramal.Text = ""
Me.Text_niver.Text = ""
Me.Text_funcao.Text = ""
Me.Text_codfuncao.Text = ""
Me.Text_gratificacao.Text = ""
Me.Text_orgao.Text = ""
Me.Text_cargo.Text = ""
Me.Text_coordenacao.Text = ""
Me.Text_email.Text = ""
Me.Text_idcliente.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 0)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 1) <> "" Then Me.Text_nome.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 1)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 2) <> "" Then Me.Text_siape.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 2)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 3) <> "" Then Me.Text_cpf.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 3)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 4) <> "" Then Me.Text_funcao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 4)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 5) <> "" Then Me.Text_coordenacao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 5)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 6) <> "" Then Me.Text_ramal.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 6)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 7) <> "" Then Me.Text_email.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 7)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 8) <> "" Then Me.Text_colaborador.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 8)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 9) <> "" Then Me.Text_celular.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 9)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 10) <> "" Then Me.Text_niver.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 10)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 11) <> "" Then Me.Text_codfuncao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 11)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 12) <> "" Then Me.Text_gratificacao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 12)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 13) <> "" Then Me.Text_orgao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 13)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 14) <> "" Then Me.Text_cargo.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 14)
End Sub
_____________________________________________________________________________________________________
Private Sub Text_pesquisar_Change()
Me.Text_bt.Text = StrConv(Me.Label_pesquisar.Caption, vbProperCase)
Call PermissaoCliente
If PermissaoBotao.PermissaoCliente = True Then
Call conectar
Dim linha As Integer
Dim i As Integer
i = 4
Planilha2.Range("a4:i33") = ""
If Me.Text_pesquisar.Text <> "" Then
Set tabela = conexao.Execute("select * from cliente where nome like '" & Me.Text_pesquisar.Text & "%'")
Else
Set tabela = conexao.Execute("select * from cliente")
End If
linha = 0
Me.ListBox_cliente.Clear
Do Until tabela.EOF
Me.ListBox_cliente.AddItem tabela("id_cliente")
If tabela("nome") <> "" Then
Me.ListBox_cliente.List(linha, 1) = tabela("nome")
Planilha2.Range("a" & i) = tabela("nome")
End If
If tabela("siape") <> "" Then
Me.ListBox_cliente.List(linha, 2) = tabela("siape")
Planilha2.Range("d" & i) = tabela("siape")
End If
If tabela("cpf") <> "" Then
Me.ListBox_cliente.List(linha, 3) = tabela("cpf")
Planilha2.Range("e" & i) = tabela("cpf")
End If
If tabela("funcao") <> "" Then
Me.ListBox_cliente.List(linha, 4) = tabela("funcao")
Planilha2.Range("f" & i) = tabela("funcao")
End If
If tabela("coordenacao") <> "" Then
Me.ListBox_cliente.List(linha, 5) = tabela("coordenacao")
Planilha2.Range("i" & i) = tabela("coordenacao")
End If
If tabela("ramal") <> "" Then
Me.ListBox_cliente.List(linha, 6) = tabela("ramal")
Planilha2.Range("n" & i) = tabela("ramal")
End If
If tabela("email") <> "" Then
Me.ListBox_cliente.List(linha, 7) = tabela("email")
Planilha2.Range("o" & i) = tabela("email")
End If
If tabela("colaborador") <> "" Then
Me.ListBox_cliente.List(linha, 8) = tabela("colaborador")
Planilha2.Range("r" & i) = tabela("colaborador")
End If
If tabela("celular") <> "" Then
Me.ListBox_cliente.List(linha, 9) = tabela("celular")
Planilha2.Range("s" & i) = tabela("celular")
End If
If tabela("niver") <> "" Then
Me.ListBox_cliente.List(linha, 10) = tabela("niver")
Planilha2.Range("t" & i) = tabela("niver")
End If
If tabela("codfuncao") <> "" Then
Me.ListBox_cliente.List(linha, 11) = tabela("codfuncao")
Planilha2.Range("u" & i) = tabela("codfuncao")
End If
If tabela("gratificacao") <> "" Then
Me.ListBox_cliente.List(linha, 12) = tabela("gratificacao")
Planilha2.Range("v" & i) = tabela("gratificacao")
End If
If tabela("orgao") <> "" Then
Me.ListBox_cliente.List(linha, 13) = tabela("orgao")
Planilha2.Range("w" & i) = tabela("orgao")
End If
If tabela("cargo") <> "" Then
Me.ListBox_cliente.List(linha, 14) = tabela("cargo")
Planilha2.Range("x" & i) = tabela("cargo")
End If
i = i + 1
linha = linha + 1
tabela.MoveNext
Loop
tabela.Close
Else
MsgBox "Usuário sem permissão para " & Me.Text_bt, , "Controle de Permissões"
End If
End Sub
Ja tentei acrescentar a seguinte linha (ListBox_cliente.List = Range("A4:AZ100").Value), mas mesmo assim apresenta um novo erro, no qual, como se o excel não conseguisse fazer um vinculação com o meu bando de dados no access. Já fiz trocentas pesquisas e constatei que era o famoso problema com a Listbox com mais de 10 colunas. Também fiz um pequeno teste colocando somente 9 colunas e funcionou perfeitamente, mas a partir da 10ª ele apresenta o erro. Poderiam me ajudar ? Desde já o meu grande abraço a todos.
Pode ser que essa minha dúvida tenha sido respondida em algum outro tópico, mas como sou iniciante em VBA ainda não consegui rodar meu formulário devido a esse "Erro em tempo de execução '380' - Não foi possível definir a propriedade List. Valor de propriedade inválido." Sendo assim, venho buscar essa pequena ajuda com o conhecimento avançado de vocês.
Segue abaixo o meu código:
Private Sub ListBox_cliente_Click()
Me.Text_idcliente.Text = ""
Me.Text_nome.Text = ""
Me.Text_colaborador.Text = ""
Me.Text_siape.Text = ""
Me.Text_cpf.Text = ""
Me.Text_celular.Text = ""
Me.Text_ramal.Text = ""
Me.Text_niver.Text = ""
Me.Text_funcao.Text = ""
Me.Text_codfuncao.Text = ""
Me.Text_gratificacao.Text = ""
Me.Text_orgao.Text = ""
Me.Text_cargo.Text = ""
Me.Text_coordenacao.Text = ""
Me.Text_email.Text = ""
Me.Text_idcliente.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 0)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 1) <> "" Then Me.Text_nome.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 1)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 2) <> "" Then Me.Text_siape.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 2)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 3) <> "" Then Me.Text_cpf.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 3)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 4) <> "" Then Me.Text_funcao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 4)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 5) <> "" Then Me.Text_coordenacao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 5)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 6) <> "" Then Me.Text_ramal.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 6)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 7) <> "" Then Me.Text_email.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 7)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 8) <> "" Then Me.Text_colaborador.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 8)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 9) <> "" Then Me.Text_celular.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 9)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 10) <> "" Then Me.Text_niver.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 10)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 11) <> "" Then Me.Text_codfuncao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 11)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 12) <> "" Then Me.Text_gratificacao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 12)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 13) <> "" Then Me.Text_orgao.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 13)
If Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 14) <> "" Then Me.Text_cargo.Text = Me.ListBox_cliente.List(Me.ListBox_cliente.ListIndex, 14)
End Sub
_____________________________________________________________________________________________________
Private Sub Text_pesquisar_Change()
Me.Text_bt.Text = StrConv(Me.Label_pesquisar.Caption, vbProperCase)
Call PermissaoCliente
If PermissaoBotao.PermissaoCliente = True Then
Call conectar
Dim linha As Integer
Dim i As Integer
i = 4
Planilha2.Range("a4:i33") = ""
If Me.Text_pesquisar.Text <> "" Then
Set tabela = conexao.Execute("select * from cliente where nome like '" & Me.Text_pesquisar.Text & "%'")
Else
Set tabela = conexao.Execute("select * from cliente")
End If
linha = 0
Me.ListBox_cliente.Clear
Do Until tabela.EOF
Me.ListBox_cliente.AddItem tabela("id_cliente")
If tabela("nome") <> "" Then
Me.ListBox_cliente.List(linha, 1) = tabela("nome")
Planilha2.Range("a" & i) = tabela("nome")
End If
If tabela("siape") <> "" Then
Me.ListBox_cliente.List(linha, 2) = tabela("siape")
Planilha2.Range("d" & i) = tabela("siape")
End If
If tabela("cpf") <> "" Then
Me.ListBox_cliente.List(linha, 3) = tabela("cpf")
Planilha2.Range("e" & i) = tabela("cpf")
End If
If tabela("funcao") <> "" Then
Me.ListBox_cliente.List(linha, 4) = tabela("funcao")
Planilha2.Range("f" & i) = tabela("funcao")
End If
If tabela("coordenacao") <> "" Then
Me.ListBox_cliente.List(linha, 5) = tabela("coordenacao")
Planilha2.Range("i" & i) = tabela("coordenacao")
End If
If tabela("ramal") <> "" Then
Me.ListBox_cliente.List(linha, 6) = tabela("ramal")
Planilha2.Range("n" & i) = tabela("ramal")
End If
If tabela("email") <> "" Then
Me.ListBox_cliente.List(linha, 7) = tabela("email")
Planilha2.Range("o" & i) = tabela("email")
End If
If tabela("colaborador") <> "" Then
Me.ListBox_cliente.List(linha, 8) = tabela("colaborador")
Planilha2.Range("r" & i) = tabela("colaborador")
End If
If tabela("celular") <> "" Then
Me.ListBox_cliente.List(linha, 9) = tabela("celular")
Planilha2.Range("s" & i) = tabela("celular")
End If
If tabela("niver") <> "" Then
Me.ListBox_cliente.List(linha, 10) = tabela("niver")
Planilha2.Range("t" & i) = tabela("niver")
End If
If tabela("codfuncao") <> "" Then
Me.ListBox_cliente.List(linha, 11) = tabela("codfuncao")
Planilha2.Range("u" & i) = tabela("codfuncao")
End If
If tabela("gratificacao") <> "" Then
Me.ListBox_cliente.List(linha, 12) = tabela("gratificacao")
Planilha2.Range("v" & i) = tabela("gratificacao")
End If
If tabela("orgao") <> "" Then
Me.ListBox_cliente.List(linha, 13) = tabela("orgao")
Planilha2.Range("w" & i) = tabela("orgao")
End If
If tabela("cargo") <> "" Then
Me.ListBox_cliente.List(linha, 14) = tabela("cargo")
Planilha2.Range("x" & i) = tabela("cargo")
End If
i = i + 1
linha = linha + 1
tabela.MoveNext
Loop
tabela.Close
Else
MsgBox "Usuário sem permissão para " & Me.Text_bt, , "Controle de Permissões"
End If
End Sub
Ja tentei acrescentar a seguinte linha (ListBox_cliente.List = Range("A4:AZ100").Value), mas mesmo assim apresenta um novo erro, no qual, como se o excel não conseguisse fazer um vinculação com o meu bando de dados no access. Já fiz trocentas pesquisas e constatei que era o famoso problema com a Listbox com mais de 10 colunas. Também fiz um pequeno teste colocando somente 9 colunas e funcionou perfeitamente, mas a partir da 10ª ele apresenta o erro. Poderiam me ajudar ? Desde já o meu grande abraço a todos.