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

Pesquisa Com evento afterupdate [Resolvido]

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
RAFAEL AMORIM
Colaborador
Colaborador
Mensagens: 69
Registrado em: Sáb Jul 22, 2017 10:17 am

Pesquisa Com evento afterupdate [Resolvido]

Mensagem por RAFAEL AMORIM »

salve, galera.

Gostaria de agradecer desde já pela atenção!

Seguinte:

No cód do evento afterupdate, abaixo, do "frm_rbpa" tenho a instrução para que quando o "txt_periodo" for preenchido com alguma data que esteja na planilha..então ao mudar o foco txtbox os demais txtbox's: "txt_rpa", "txt_fspa" sejam preenchidos com os demais dados do registro.


faço a chamada deste evento no evento initialize:

Código: Selecionar todos

Private Sub txt_periodo_AfterUpdate()

Dim lngPriLin, lngUltLin, lngLoopLin       As Long
Dim datPeriodo                             As Date
Dim vlrRPA, vlrFSPA                        As Currency
Dim strbusca                               As String


If txt_Peridodo = "" Or IsEmpty(txt_periodo) Then Exit Sub
'If txt_rpa = "" Or IsEmpty(txt_rpa) Then Exit Sub
'If txt_fspa = "" Or IsEmpty(txt_fspa) Then Exit Sub

lngPriLin = 2


datPeriodo = CDate(txt_periodo.Text)
vlrRPA = txt_rpa.Text
vlrFSPA = txt_fspa.Text


With wshComum

    lngUltLin = .Cells(.Rows.Count, 2).End(xlUp).Row

    For lngLoopLin = lngPriLin To lngUltLin Step 1
        strbusca = .Cells(lngLoopLin, 2)

        If strbusca = datPeriodo Then
            vlrRPA = CCur(.Cells(lngLoopLin, 3))
            vlrFSPA = CCur(.Cells(lngLoopLin, 4))
        End If
   Next lngLoopLin
End With

End Sub
Anexos
SIMPLES NACIONAL.rar
(205.23 KiB) Baixado 227 vezes
Editado pela última vez por RAFAEL AMORIM em Qui Mai 24, 2018 11:58 am, em um total de 1 vez.


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.


srobles
Jedi
Jedi
Mensagens: 805
Registrado em: Qua Mai 06, 2015 7:39 pm

Re: Pesquisa Com evento afterupdate

Mensagem por srobles »

Rafael,

Conforme respondido no Fórum Planilhando, usei a rotina abaixo em meus testes e obtive o resultado esperado.

Código: Selecionar todos

Private Sub txt_periodo_AfterUpdate()
    Dim lngPriLin, lngUltLin, lngLoopLin       As Long
    Dim datPeriodo                             As Date
    Dim strbusca                               As String
    
    lngPriLin = 2
    
    With Me
        On Error GoTo trataErro
        datPeriodo = .txt_periodo.Text
        txt_rpa = ""
        txt_fspa = ""
    End With
    
    With wshComum
        lngUltLin = .Cells(.Rows.Count, 2).End(xlUp).Row
    End With
    
    With wshComum
        For lngLoopLin = lngPriLin To lngUltLin Step 1
            strbusca = .Cells(lngLoopLin, 2)
    
            If strbusca = datPeriodo Then
                Me.txt_rpa = CCur(.Cells(lngLoopLin, 3))
                txt_fspa = CCur(.Cells(lngLoopLin, 4))
                Exit For
            End If
        Next lngLoopLin
    End With
    
trataErro:
If Err = 13 Then
    Me.txt_periodo = ""
    Me.txt_rpa = ""
    Me.txt_fspa = ""
End If
End Sub
Espero ter ajudado e que tenha obtido o resultado esperado.

Abs


RAFAEL AMORIM
Colaborador
Colaborador
Mensagens: 69
Registrado em: Sáb Jul 22, 2017 10:17 am

Re: Pesquisa Com evento afterupdate [Resolvido]

Mensagem por RAFAEL AMORIM »

vlww. srobles...muito obrigado meu caro amigo!


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