If you are given money for something specific, you must spend it on that thing. This is known as ‘restricted’ income. Examples of restricted income might be a grant from a trust or foundation, or a donation from someone specifically to spend on a particularly project. Some income (e.g. money earned from ticket sales, or public donations from a sponsored event) can be classed as ‘unrestricted’ income, meaning it can be spent on anything that comes under your charitable objectives. Where the restriction has been defined by the donor, you must be able to prove that any restricted income has been spent on what it was donated for.
You cannot fundraise for something in particular and then spend the money you raise on something else. If your fundraising campaign raises more money than it needs for a specific cause then you must follow Charity Commission rules to identify a new purpose: Charity fundraising appeals: using donations when you’ve raised more than you need. Likewise, if your appeal doesn’t raise enough money you must either return the donations or follow the Charity Commission rules to identify a new purpose: Charity fundraising appeals: using donations when you have not raised enough money or you cannot achieve your appeal purpose.
NCVO gives a simple overview of fund accounting here: What’s different about charity finance | NCVO