on the cart page, add an if statement around the checkout button to check the c=total cart quantoty and only show the checkout button if the quantity is 40 or less:
<?php if($<your cart name>->TotalColumn("Quantity") <= "40") { ?>
<checkout button>
<?php } ?>
you can use a similar if statement to show an error message if the quantity is greater than 40:
<?php if($<your cart name>->TotalColumn("Quantity") > "40") { ?>
error message
<?php } ?>
in both of these if statements, replace "<your cart name>" with the name of your eCart object.