The theory of modular forms, in particular theta functions, and coding theory are in a remarkable way connected. The connection is established by defining a suitable lattice corresponding to the given code, and considering its theta function. First we define some special theta functions, and determine transformation formulas. Then it is proved that the theta function of the lattice corresponding to the code can be expressed in terms of the Lee weight enumerator. In particular if the code is self-dual and the length is a multiple of this theta function is a modular form for some subgroup of the modular group. Using the known structure of this space of modular forms we can derive linear relations between the coefficients of the Lee weight enumerator. And from these relations we can get an upper bound for the minimal Lee distance of self-dual -ary codes.