TITLE: $f:X\rightarrow Y$ is a closed immersion iff $f:f^{-1}(U_i)\rightarrow U_i$ is a closed immersion.
QUESTION [5 upvotes]: I came across the following property of closed immersions on Wikipedia -

A morphism $f:Z\rightarrow X$ is a closed immersion iff for some
  (equivalently every) open covering $X=\bigcup U_j$ the induced map
  $f:f^{-1}(U_j)\rightarrow U_j$ is a closed immersion.

I am having trouble with the "equivalenty every cover" part - assuming that the property of a morphism being a closed immersion holds for some open cover iff it holds for every cover I am able to prove the above result as follows -
If $f$ is a closed immersion then cover $X$ just by $X$ and we have found "some" cover of $X$ satisfying the induced map is a closed immersion.
Conversely, if there is "some" cover for which the induced map is a closed immersion then as it is true (as per the assumption I made) for every cover, we can take the cover to be $X$ and are done. (I hope this is correct!)
Now all I have to do is prove the assumption. But I have no idea where to start. 
I know this lemma - Let $X$ be a scheme and let $\mathcal P$ be a property. Suppose $\mathcal P$ satisfies the following conditions -

If $\mathcal P$ is true for $\operatorname{Spec }R$ then it is true for $\operatorname{Spec }R_g$ for every $g\in R$
If $\langle g_1,\cdots,g_n\rangle=R$ and $\mathcal P$ is true for each $\operatorname{Spec }R_{g_i}$ then $\mathcal P$ is true for $\operatorname{Spec }R$

Let $X=\bigcup U_i$ be an affine open cover of $X$ and suppose $\mathcal P$ is true for each $U_i$ then $\mathcal P$ is true for every affine open subset of $X$.
But this Lemma can only be applied for an affine open cover and Wikipedia's statement about closed immersions is for every open cover so I don't know how to prove it. Any help will be greatly appreciated.
Thank you.

REPLY [2 votes]: If you are a Vakilian, here is how to do it using the affine communication lemma. First note that by 7.3.4 in Vakil's notes we have that the affine property of a morphism is affine local on the target. 
Let $X = \mathrm{Spec A}$ and $Y = \mathrm{Spec B}$, $\pi: X \to Y$. Now let $D(f) \subset Y$. Then $\pi^{-1}(D(f)) = D(\pi^{\#}(f))$. 
Suppose that $\pi^{\#}: B \to A$ is surjective. Then $B_f \to A_{\pi^{\#}(f)}$ is surjective. 
Now suppose that there exist $f_1,\dots,f_k$ in $B$ s.t $(f_1,\dots,f_k) = B$ such that for all $i$ we have that $B_{f_i} \to A_{\pi^{\#}(f_i)}$ is surjective. Then by algebra for all $a \in A$ we have there exist $n_i$ s.t ${\pi^{\#}(f_i)}^{n_i}a \in Im(\pi^{\#})$. Since $({\pi^{\#}(f_1)}^{n_1},\dots,{\pi^{\#}(f_k)}^{n_k})_{Im(\pi^{\#})} \supset \{1\}$ we have that $a \in Im(\pi^{\#})$. We have shown surjectivity of $\pi^{\#}: B \to A$.