Hi

I am with great problem,

I am see a system that the other analysta put
a click event from button, It star a function that does many things, but after start a same click event, how I termine this event when occur 1 condition:
example I have 2 textbox
textbox1, and textbox 2 and a button command
when the textbox 1 and 2 were full, I want stop this recursive call

Sub cmd_Conf_Paciente_Click()
Dim paciente As New cls_Paciente
paciente.Codigo = IIf(txt_Cod_Paciente.Text <> "", txt_Cod_Paciente.Text, Null)
paciente.Descricao = txt_Nome_Paciente.Text
paciente.Nascimento = msk_Nascimento
paciente.Tela = Me

paciente.Pesquisa

Call SL_FILL_GRID_PAC
cmd_Conf_Paciente.Enabled = False
Exit Sub


Errcmd_Conf_Paciente_Click:
If Err.Number = 5 Then
Resume Next
End If
MousePointer = vbNormal
Set rs = Nothing
Set qd = Nothing
SG_Trata_Erro Err.Number, Me.Name
End Sub
Public Sub Pesquisa()

'Carrega o recordset que sera utilizado para popular
'a tela de pesquisa

On Error GoTo ErrPesquisa


'SG_Pesquisa por codigo
If Not IsNull(Codigo) And _
Trim(Codigo) <> "" Then
'==========>
Set qd = New ADODB.Command
Set rs = New ADODB.Recordset
With qd
If boo_Informix_Ativo Then
.ActiveConnection = G_Database
.CommandText = "sp1_se_ag11_02"
ElseIf boo_SQLServer_Ativo Then
.ActiveConnection = G_SQLServer
.CommandText = "sp2_se_ag11_02"
Else
Exit Sub
End If
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter(, adInteger, adParamInput)
qd(0) = Codigo
End With
Set rs = qd.Execute
If rs(0) = 0 Then
mEncontrado = True
End If


' Pesquisa por data de nascimento
'
ElseIf Nascimento <> "__/__/____" And Len(Descricao) = 0 Then
Set qd = New ADODB.Command
Set rs = New ADODB.Recordset
With qd
If boo_Informix_Ativo Then
.ActiveConnection = G_Database
.CommandText = "sp1_se_ag11_06"
ElseIf boo_SQLServer_Ativo Then
.ActiveConnection = G_SQLServer
.CommandText = "sp2_se_ag11_06"
Else
Exit Sub
End If
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter(, adChar, adParamInput, 60)
qd(0) = Format(Nascimento, "yyyy-mm-dd")
End With
Set rs = qd.Execute
If rs(0) = 0 Then
' If rs(4) = "PA01" Then
' Codigo = rs(1)
' Pac_tabela = rs(4)
' Confirma
' Else
mEncontrado = True
' End If
End If

'SG_Pesquisa por nome

Else
'==========>
Set qd = New ADODB.Command
Set rs = New ADODB.Recordset
With qd
If boo_Informix_Ativo Then
.ActiveConnection = G_Database
.CommandText = "sp1_se_ag11_04"
ElseIf boo_SQLServer_Ativo Then
.ActiveConnection = G_SQLServer
.CommandText = "sp2_se_ag11_04"
Else
Exit Sub
End If
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter(, adChar, adParamInput, 60)
qd(0) = Descricao
End With
Set rs = qd.Execute
If rs(0) = 0 Then
If rs(4) = "PA01" Then
Codigo = rs(1)
Pac_tabela = rs(4)
Confirma
Else
mEncontrado = True
End If
End If


End If

'Chama tela de SG_Pesquisa
Call SG_Pesquisa(fTela, rs, fTela.cmd_Pesq_Paciente, True)

Exit Sub

ErrPesquisa:
SG_Trata_Erro Err.Number, "cls_Paciente"
Exit Sub

End Sub

other procedure has command button that

If G_Controle.Name = "cmd_Pesq_Paciente" Then
G_Tela.txt_Cod_Paciente = var_Grade_Controles(1)
G_Tela.txt_Nome_Paciente = var_Grade_Controles(2)
If regExame.bAgendados And Not regExame.bAgenda Then
G_Tela.msk_Nascimento = IIf(IsDate(var_Grade_Controles(3)), var_Grade_Controles(3), "__/__/____")
End If
G_Tela.cmd_Conf_Paciente_Click

End If




thank you in advance