I have writen the code under to be able to fill automatically the field "ARTICLE" when the field "CBARRE" is field first.
This code works perfectly but when I input a wrong CBARRE number or when I live the field blank, I receive an error message "Error 94 - Unvalid use of Null"
Can you help me replace this error with a personnalized message box or just ignore it.
Private Sub CBARRE_Exit(Cancel As Integer)
Dim txtARTICLE1 As String
Dim txtPVUTTC1 As String
txtARTICLE1 = DLookup("ARTICLE1", "tblCBARRE", "CBARRE1 =[CBARRE]")
txtPVUTTC1 = DLookup("PVUTTC1", "tblCBARRE", "CBARRE1 =[CBARRE]")
If (Not IsNull(txtARTICLE1)) Then Me![ARTICLE] = txtARTICLE1
If (Not IsNull(txtPVUTTC1)) Then Me![PVUTTC] = txtPVUTTC1
But I believe in avoiding errors that you can anticipate, and this is an instance of that. You get an error because a String variable can't accept a Null, which is what the DLookup will return when it can't find a result. Changing String to Variant will avoid the error.