On the $p$-rank of the incidence matrix of a balanced or partially balanced incomplete block design and its applications to error correcting codes