Just before you paint new or existing woodwork, you need to patch the area where the woodwork touches another surface. To fill in these areas, get a professional caulk gun, acrylic or latex caulk that matches the color of the paint, a bucket of water and a tile grout sponge.
Pick up a good caulk gun at a paint store that sells better grade tools. A tile grout sponge is available at ceramic tile stores. These sponges differ from standard sponges because they have nice soft rounded edges.
Cut the tip to match the size of the crack you are filling. Too big of a hole in the caulk tube and you will have a real mess. Caulk about two feet at a time. Wipe off the excess caulk with your finger. Then, follow with the damp sponge to smooth out the patch and remove any caulk from the surrounding woodwork.
Done right, your paint job will look a lot better without the gaps between the woodwork and the walls.