Hi HopeLass ~ has your kitty been diagnosed with dementia? If so, there are some things you can do to help her. Dementia is a failing of cognitive abilities & memory function, particularly short term memory, and one of the first signs is a break down of toilet training. This could be why sometimes she remembers where the litter tray is & sometimes forgets & goes somewhere else.
Firstly, you must make sure that you thoroughly clean any areas that she has messed on, because otherwise the smell could well attract her to go there again.
Make sure you have several litter trays around, especially one in the room she normally sleeps in. Not too near her bed, but near enough for her to easily see or smell it. Keep it clean, make sure that it is the type that she can easily get in & out of (some cats get a bit stiff with old age & find it difficult to get in & out of trays with high edges, or where they can't turn around).
If your cat has a preference for one room in your house, make sure that she has everything she needs in that room, i.e. a variety of comfy beds at different heights in warm, draft-free places, but accessible so she can get up into them, food, water, litter tray, scratching post or mat if she uses one.
Even when their senses start to fail with age, cats can usually still follow scent trails around ~ so you could try using your cats bedding or a cloth rubbed around her face, to leave scent trails around your house to, e.g. the litter tray, the food/water bowls. Just rub the bedding or cloth at head height along walls, door posts, etc as a trail to her litter tray. Keep topping these up, daily if possible & concentrate on the areas where she rubs her face & on entrances & exits as well.
Try not to make any changes to the set up in your house ~ keep furniture in the same place, try not to buy new furniture, soft furnishings etc for a while. Try not to have too many strangers coming & going, bringing strange & confusing smells into her world.
Sometime a bit of "occupational therapy" can help too. If your cat used to like to play with a certain toy, or chase something ~ try to keep her doing this but in a much more low key way. E.g. if she used to like chasing a ping pong ball, try rolling one across the floor towards her so she can trap it in her paws. If she liked fishing rod toys, try dangling one just in front of her, but within reach so she can grab it. If she can use her paws to scoop a tasty treat out of an cardboard tube, try that. Sometimes these long-remembered games & feelings of pleasure can still be invoked in cats that have long since stopped playing, but the neural circuits that were used in these games are still functioning, & just need a "kick start" to get them going again. And long term memory is more likely to still be working so things from years ago that she used to do a lot may still be remembered. Also any form of gentle physical exercise that she feels capable of will be good for co-ordination, keeping muscles working & helping her physical condition.
As cats get older they sometimes have trouble grooming themselves & keeping clean, so you may have to help her with that ~ but keep grooming to short sessions only & be very gentle.
Several smaller meals a day may be better for some aging cats (& you can indulge them with their favourite treats now & again if there's no medical reason not to

).
If your cat likes to go outside on warm days, take them on short walks round the garden, maybe sit out in the sun with them & have a cuppa ~ your cat is likely to feel safer & happier with you nearby.
And remember ~ these are our feline senior citizens ~ they have given us a lot of pleasure over their lives so the least we can do is make sure they are safe, pain-free & happy in their golden years

.