It depends on how this code is entered, if this is a type a code in a box from a computer keyboard or a type a code on a physical keypad that requires a user to physically brute force it.
If it has scope to be attacked by a computer a six digit numeric pin could be cracked in minutes, 6 digits gives 1111110 password combinations, at 766 keys per second, your pin is cracked in 24 minutes, at 4 digits it's 14 seconds. You can run numbers yourself through this calculator to give you an idea http://calc.opensecurityresearch.com/
With physical entry it's much more demanding time wise and a human will give up long before a computer will. You must have some sort of lock out after multiple failed attempts, as ATMs do - typically locking you out after three attempts. So, it's not necessarily the length that is hugely important beyond the trivially guessable, ie it should be at least four or more. The chances of hitting a 4 digit code in three guesses are extremely small, so something in the range of 4 - 8 i would have thought should suit your application offering a difficult to guess PIN with low effort to enter.