Try this - it will replace any empty values with zeros
Public Sub INFO_PROTO(NO_POLICE As String)
Dim RECSET As New ADODB.Recordset
RECSET.Open "select proto.b_perf_cma as b_perf_cma, proto.b_perf_supp_ann as " & _
" b_perf_supp_ann, proto.b_perf_ctrat_gar as b_perf_ctrat_gar " & _
"from db_dossier sousc, db_produit prod, db_protocole proto" & _
" where sousc.no_police = '" & NO_POLICE & "' and sousc.cd_dossier = 'SOUSC' " & _
" and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') and " & _
"sousc.is_produit = prod.is_produit and sousc.is_protocole = proto.is_protocole ", _
cnn_Pegase, adOpenDynamic, adLockBatchOptimistic
'use a With block to remove repetition
With ThisWorkbook.Worksheets("1 - Feuille de Suivi Commercial")
If Not RECSET.EOF Then
.Range("test").Value = CheckValue(RECSET.Fields("b_perf_cma").Value)
.Range("test2").Value = CheckValue(RECSET.Fields("b_perf_supp_ann").Value)
.Range("test3").Value = CheckValue(RECSET.Fields("b_perf_ctrat_gar").Value)
Else
.Range("test").Value = "NC"
.Range("test2").Value = "NC"
.Range("test3").Value = "NC"
End If
End With
RECSET.Close
End Sub
Function CheckValue(v)
'Default to zero if null
CheckValue = iif(Len(v) = 0, 0, v)
End Function
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…