VERIFICAR ANTES DE FAZER O DELETE

MATHEUSGE 14/12/2011 23:16:03
#391388
Galera, sou iniciante em VB6 ;x ...

Tenho o seguinte código:

On Error GoTo erro
If txtCdCliente.Text = [Ô][Ô] Then
MsgBox [Ô]Selecione um cliente para excluir.[Ô], vbInformation, [Ô]Manutenção Cliente[Ô]
Else
If MsgBox([Ô]Tem certeza que deseja excluir este cliente?[Ô], vbYesNo + vbInformation, [Ô]Manutenção Cliente[Ô]) = vbYes Then
con.BeginTrans
con.Execute [Ô]DELETE FROM Cliente WHERE CdCliente = [ô][Ô] & txtCdCliente.Text & [Ô][ô];[Ô]
con.CommitTrans
MsgBox [Ô]Registro Deletado![Ô]
rs.NextRecordset
MostraDados
Exit Sub
erro:
MsgBox [Ô]Número : [Ô] & Str$(Err.Number) & vbCrLf & _
[Ô]Descrição : [Ô] & Err.Description & vbCrLf & _
[Ô]Gerado por : [Ô] & Err.Source, vbCritical
Else
Exit Sub
End If
End If

Certo?
Gostária de uma dica para verificar se o código do Cliente existe antes de deletar; No seguinte código ele mostra a mensagem [Ô]Excluido com sucesso![Ô] independente do [Ô]CodCliente[Ô] fornecido, gostária que, ao não existir o [Ô]CodCliente[Ô] mostra-se [Ô]Código incorreto[Ô].

Agradeço desde já
LUIZCOMINO 15/12/2011 00:01:55
#391389
Resposta escolhida
Segue amigão

[ô]Inicio=======================================
Dim rs As New ADODB.Recordset

On Error GoTo erro
If txtCdCliente.Text = [Ô][Ô] Then
MsgBox [Ô]Selecione um cliente para excluir.[Ô], vbInformation, [Ô]Manutenção Cliente[Ô]
Else
If MsgBox([Ô]Tem certeza que deseja excluir este cliente?[Ô], vbYesNo + vbInformation, [Ô]Manutenção Cliente[Ô]) = vbYes Then

[ô]Verificando se o Registro Existe
rs.Open [Ô]Select * from Cliente WHERE CdCliente = [ô][Ô] & txtCdCliente.Text & [Ô][ô];[Ô], con, adOpenKeyset, adLockReadOnly

If rs.eof then
Msgbox [Ô]Esse Registro Não Existe![Ô]
Exit Sub
End If

con.BeginTrans
con.Execute [Ô]DELETE FROM Cliente WHERE CdCliente = [ô][Ô] & txtCdCliente.Text & [Ô][ô];[Ô]
con.CommitTrans
MsgBox [Ô]Registro Deletado![Ô]
rs.NextRecordset
MostraDados
Exit Sub
erro:
MsgBox [Ô]Número : [Ô] & Str$(Err.Number) & vbCrLf & _
[Ô]Descrição : [Ô] & Err.Description & vbCrLf & _
[Ô]Gerado por : [Ô] & Err.Source, vbCritical
Else
Exit Sub
End If
End If
[ô]=====================================================
VALDEMIRLUZ 15/12/2011 01:14:46
#391391
vc tambem pode pegar o retorno do .EXECUTE (ou seja: 0 ou 1)
exemplo:
dim intRetorno as integer
con.Execute [Ô]DELETE FROM Cliente WHERE CdCliente = [ô][Ô] & txtCdCliente.Text & [Ô][ô];[Ô], intRetorno
if intRetorno <> 0 then
msgbox [Ô]Cliente Excluido![Ô]
else
msgbox [Ô]Cliente Inexistente![Ô]
end if
MATHEUSGE 15/12/2011 01:28:57
#391392
Vlw *-*, me ajudaram muito!!
Tópico encerrado , respostas não são mais permitidas