Inquiridor
ERRO AO EXECUTAR VBA

Pergunta
-
Boa tarde amigos!
Tenho um sistema em VBA e ele contem um botão de "pesquisar" e "editar". Quando clico no botão "pesquisar" e informo o n° do chamado, ele traz toda informação desse chamado, inclusive n° da reserva e data de retirada. Quando altero a data de retirada ex. do dia 03/04 para 15/04 ele altera e depois clico no botão "Editar" para concluir a ação.Mas se eu tiver uma pessoa com o mesmo nome so que com n° de chamado e reserva diferente, ele faz alateração nesse outro, alterando além da dat de retirada, o n° do chamado e reserva, ficando em duplicidade e a data que era para alterar no chamado informado, ele não altera.
Não sei se consegui me fazer entender, mas segue abaixo os códigos dos botões de pesquisar e editar.
Pesquisar:
Private Sub btpesquisar_Click()
On Error GoTo Erro
Dim Pesquisa As String
Pesquisa = InputBox("Digite o que deseja pesquisar!", "PESQUISAR")
Dim Linha As Double
Linha = 2446
With Plan1
Do
Linha = Linha + 1
If .Cells(Linha, 1).Value = Pesquisa Or .Cells(Linha, 2).Value = Pesquisa Or .Cells(Linha, 3).Value = Pesquisa _
Or .Cells(Linha, 4).Value = Pesquisa Or .Cells(Linha, 5).Value = Pesquisa Or .Cells(Linha, 6).Value = Pesquisa _
Or .Cells(Linha, 7).Value = Pesquisa Or .Cells(Linha, 8).Value = Pesquisa Or .Cells(Linha, 9).Value = Pesquisa _
Or .Cells(Linha, 10).Value = Pesquisa Or .Cells(Linha, 11).Value = Pesquisa Or .Cells(Linha, 12).Value = Pesquisa _
Or .Cells(Linha, 13).Value = Pesquisa Or .Cells(Linha, 14).Value = Pesquisa Or .Cells(Linha, 15).Value = Pesquisa _
Or .Cells(Linha, 16).Value = Pesquisa Or .Cells(Linha, 17).Value = Pesquisa Or .Cells(Linha, 18).Value = Pesquisa Then
txtid = .Cells(Linha, 1).Value
txtnome.Text = .Cells(Linha, 2).Value
cbbcidade.Text = .Cells(Linha, 3).Value
cbbuf.Text = .Cells(Linha, 4).Value
cbbregiao.Text = .Cells(Linha, 5).Value
txtchamado.Text = .Cells(Linha, 6).Value
txtreserva.Text = .Cells(Linha, 7).Value
txtdretirada = .Cells(Linha, 8).Value
txthretirada.Text = VBA.Format(.Cells(Linha, 9).Value, "HH:MM")
cbbempresa.Text = .Cells(Linha, 10).Value
cbbveiculos.Text = .Cells(Linha, 11).Value
txtddevolucao = .Cells(Linha, 12).Value
txthdevolucao.Text = VBA.Format(.Cells(Linha, 13).Value, "HH:MM")
txtdiarias.Text = .Cells(Linha, 14).Value
txttipo.Text = .Cells(Linha, 15).Value
cbblocadora.Text = .Cells(Linha, 16).Value
txtano = .Cells(Linha, 17).Value
txtobs.Text = .Cells(Linha, 18).Value
Exit Sub
End If
Loop Until .Cells(Linha, 1).Value = ""
MsgBox "Não encontrado!", vbInformation, "PESQUISA"
End With
Exit Sub
Erro:
MsgBox "Erro!", vbCritical, "ERRO"
End Sub
Editar:
Private Sub bteditar_Click()
On Error GoTo Erro
If txtid = "" Or txtnome = "" Or cbbcidade = "" Or cbbuf = "" Or cbbregiao = "" Or txtchamado = "" Or txtreserva = "" _
Or txtdretirada = "" Or txthretirada = "" Or cbbempresa = "" Or cbbveiculos = "" Or txtddevolucao = "" Or txthdevolucao = "" _
Or txtdiarias = "" Or txttipo = "" Or cbblocadora = "" Then
MsgBox "Precisa preencher todos os campo!", vbCritical, "ERRO"
Exit Sub
End If
Dim ID As Double
ID = txtid
Ano = txtano
Dim Data As Date, Datadevol As Date
Data = txtdretirada.Value
Datadevol = txtddevolucao.Value
Dim Linha As Double
Linha = 2446
With Plan1
Do
Linha = Linha + 1
If .Cells(Linha, 1).Value = ID Then
.Cells(Linha, 1).Value = ID
.Cells(Linha, 2).Value = txtnome.Text
.Cells(Linha, 3).Value = cbbcidade.Text
.Cells(Linha, 4).Value = cbbuf.Text
.Cells(Linha, 5).Value = cbbregiao.Text
.Cells(Linha, 6).Value = txtchamado.Text
.Cells(Linha, 7).Value = txtreserva.Text
.Cells(Linha, 8).Value = Data
.Cells(Linha, 9).Value = txthretirada.Text
.Cells(Linha, 10).Value = cbbempresa.Text
.Cells(Linha, 11).Value = cbbveiculos.Text
.Cells(Linha, 12).Value = Datadevol
.Cells(Linha, 13).Value = txthdevolucao.Text
.Cells(Linha, 14).Value = txtdiarias.Text
.Cells(Linha, 15).Value = txttipo.Text
.Cells(Linha, 16).Value = cbblocadora.Text
.Cells(Linha, 17).Value = Ano
.Cells(Linha, 18).Value = txtobs.Text
Call Limpar
MsgBox "Editado com sucesso!", vbInformation, "EDITAR"
Exit Sub
End If
Loop Until .Cells(Linha, 1).Value = ""
MsgBox "Não encontrado!", vbInformation, "EDITAR"
End With
Exit Sub
Erro:
MsgBox "Erro!", vbCritical, "ERRO"
End SubAbs,
Kpastre
Todas as Respostas
-
Kpastre,
Esta é uma sessão dos fóruns dedicados exclusivamente ao Microsoft SQL Server, recomendo postar nas sessões de desenvolvimento para Visual Basic e C#.
Pedro Antonio Galvão Junior [MVP | MCC | MSTC | MIE | MTAC | Microsoft Evangelist | Microsoft Partner | Engenheiro de Softwares | Especialista em Banco de Dados Relacional e Data Warehouse | Professor Universitário | @JuniorGalvaoMVP | http://pedrogalvaojunior.wordpress.com]