Future wireless communication systems are expected to explore spectral bands typically used by radar systems, in order to overcome spectrum congestion of traditional communication bands. Since in many applications radar and communication share the same platform, spectrum sharing can be facilitated by joint design as dual function radar-communications system. In this paper, we propose a joint transmit beamforming model for a dual-function multiple-input-multiple-output (MIMO) radar and multiuser MIMO communication transmitter sharing the spectrum and an antenna array. The proposed dual-function system transmits the weighted sum of independent radar waveform and communication symbols, forming multiple beams towards the radar targets and the communication receivers, respectively. The design of the weighting coefficients is formulated as an optimization problem whose objective is the performance of the MIMO radar transmit beamforming, while guaranteeing that the signal-to-interference-plus-noise ratio (SINR) at each communication user is higher than a given threshold. Despite the non-convexity of the proposed optimization problem, it can be relaxed into a convex one, which can be solved in polynomial time, and we prove that the relaxation is tight. Then, we propose a reduced complexity design based on zero-forcing the inter-user interference and radar interference. Unlike previous works, which focused on the transmission of communication symbols to synthesize a radar transmit beam pattern, our method provides more degrees of freedom for MIMO radar and is thus able to obtain improved radar performance, as demonstrated in our simulation study. Furthermore, the proposed dual-function scheme approaches the radar performance of the radar-only scheme, i.e., without spectrum sharing, under reasonable communication quality constraints.