Problem is often that when you change gear, three heavy duty motors operate for a fraction of a second. This drops the battery voltage momentarily and upsets the engine ECU - and maybe then the gear change misses the very small time window. So everything has to be perfect.
If the problem continues then you may need to disconnect every plug and socket in the clutch and gear actuator circuits as the contacts can corrode inside.
This can happen as a protective precaution if something overheats, eg in hot countries or in heavy traffic.
BEFORE you disconnect the battery you must let the systems go into stand-by or you will create more 'errors'. And after you reconnect the battery you need to allow the systems to initialize before opening the doors or doing anything further.
However - for me after three attempts: I still had the snowflake and auto symbols flashing, although I could now engage 1st and reverse. These indications cleared after driving the car a very short distance (25 yards). Dunno why, but this worked for me; possibly because the alternator cut in and raised the battery volts to 14.3!
Neil Gibson reminds us that: what you might think as a transmission problem could be a symptom and not the cause.
Each electronic control unit feeds data via the BSI unit or body control module to the gearbox. A momentary glitch can have interesting results.
A recent problem with an ABS pump resulted in the sliding doors failing to open. Why should the ABS impact on the doors? The door control module won't allow operation above 3 mph. No speed reading. No door opening. The doors get blamed again!
The gearbox is the same. Virtually every power train sensor from throttle position to wheel speed can affect gear selection