How are compounds formed?
By the sharing of electron density
Atoms share their electron densities to achieve greater stability and are " joined" by the common attraction to the shared electron density.
The valance or outermost electrons of an atom are free to move in orbitals of only mathematically determined probability. These electrons are usually free to be shared with other atoms as the electrons move around the nucleus. ( Noble gases are usually an exception as the stability of the their electron configuration precludes most bonding )
The electron configuration of these valance electrons creates conditions of varying stability. The single valance electron in the IA family is very unstable and its electron density is easily shared with other atoms. The VII A atoms create a strong attraction for the electron density of other atoms in order to achieve the stability of the Noble gas elements.
By sharing the electron densities atoms can achieve greater stability in combined electron configurations. The greater stability helps to "bind" the atoms together creating bonds. Also as the positive charged nucleus of each atom is attracted to the shared electron density the force of these attractions creates the bond that forms compounds.