If the fault is intermittent like that it is far more likely to be something like the wires having chafed in that pesky P clip on top of the gearbox. If it was in the gearbox itself, you'd have the problem all the time, IMHO.
Numerous people on here have found this. One guy only got it when turning hard right (or left, faulty memory) it was the movement of the engine and gearbox in its mounts, causing the bit of the loom to flex and the exposed wire to come into contact with metal or something. Yours may have chafed slightly differently, but if it was my vehicle that is absolutely the first place i'd be looking.
Don't know if the code reader will tell you this, if this is the problem, somehow doubt it! But looking for the chafed wire will cost nothing but time and effort.
Post the codes and people like SF and JM will look at them and they really know their onions when it comes to codes etc.