diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 5c28db87dbfd8..c6ec1d5d151b0 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3765,11 +3765,10 @@ function showbarcode(&$object,$width=100)
if (empty($object->barcode_type_code) || empty($object->barcode_type_coder))
{
$result = $object->fetch_barcode();
+ //Check if fetch_barcode() failed
+ if ($result < 1) return '';
}
- //Check if fetch_barcode() failed
- if ($result < 1) return '';
-
// Barcode image
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($object->barcode_type_coder).'&code='.urlencode($object->barcode).'&encoding='.urlencode($object->barcode_type_code);
$out ='';