The stomach has a dual role to play in terms of vitamin B12 metabolism. Most famously, its parietal cells secrete intrinsic factor, a peptide that binds to vitamin B12. Intrinsic factor's role is to protect the vitamin from degradation by gastrointestinal enzymes, and to facilitate the absorption of vitamin B12 at the terminal ileum (there's a specific receptor for it there).
However, the stomach plays another, equally important role. The form of vitamin B12 that we eat is already bound to proteins, called salivary R-binders. The B12 must first be cleaved from these proteins (only to be rapidly reattached to the body's intrinsic factor, of course), and this requires an acidic pH in the stomach, amongst other things.
Thus gastric atrophy (as found for instance with chronic gastritis) leads to vitamin B12 deficiency in two ways - decreased intrinsic factor production, and a lack of adequate stomach acid production. Antacids predispose you to the second of these problems too, which is why your risk of vitamin B12 deficiency is (slightly!) raised if you take them.