Olá, estou tentando colocar sua dica na minha sub, mas não esta dando certo dá o erro:
minha Sub
Private Sub Arquivar_Click()
mobjRst.Open "SELECT rg FROM morto WHERE CODIGO = " & txtRg.Text & ", ..., ..., ..."
If mobjRst.RecordCount > 0 Then
MsgBox "Código digitado já existe", vbCritical, "Aviso"
Exit Sub
'Else
' ...
End If
mobjRst.Close: Set mobjRst = Nothing
Dim strNOME As String
Dim strRG As String
Dim lngCustID As Long
Dim lngNewSelIndex As Long
If lvwCustomer.SelectedItem Is Nothing Then
MsgBox "Não tem Nome selecionado para Arquivar.", _
vbExclamation, _
"ARQUIVAR - MORTO"
Exit Sub
End If
With lvwCustomer.SelectedItem
strNOME = .Text
strRG = .SubItems(mlngCUST_RG_IDX)
lngCustID = CLng(.SubItems(mlngCUST_ID_IDX))
End With
If MsgBox("Você tem certeza que quer Arquivar Nome '" _
& strNOME & " " & strRG & "'?", _
vbYesNo + vbQuestion, _
"Confirma Exclusão") = vbNo Then
Exit Sub
End If
mobjCmd.CommandText = "INSERT INTO Morto SELECT * FROM Customer WHERE CustID = " & lngCustID
mobjCmd.Execute
mobjCmd.CommandText = "DELETE FROM Customer WHERE CustID = " & lngCustID
mobjCmd.Execute
With lvwCustomer
If .SelectedItem.Index = .ListItems.Count Then
lngNewSelIndex = .ListItems.Count - 1
Else
lngNewSelIndex = .SelectedItem.Index
End If
.ListItems.Remove .SelectedItem.Index
If .ListItems.Count > 0 Then
Set .SelectedItem = .ListItems(lngNewSelIndex)
lvwCustomer_ItemClick .SelectedItem
Else
ClearCurrRecControls
End If
End With
' Informa o total de registros do bd
Set mobjRst = New ADODB.Recordset
mobjRst.CursorLocation = adUseClient
mobjRst.Open "Select * From Customer", mobjConn, adOpenKeyset, adLockOptimistic, adCmdText
Label25.Caption = "Total de Registros = " & mobjRst.RecordCount
End Sub
Run-time-err- 91
Object Variable or With block variable not set
Nessa linha:
mobjRst.Open "SELECT rg FROM morto WHERE CODIGO = " & txtRg.Text & ", ..., ..., ..."