Were there times when soldiers would rather have a crossbow than a gun because of lacking gun technology? Was there a time in the development of guns where crossbows were still the best ranged weapon?
It is not a precise moment, but arquebuses and other shoulder arms join bows and crossbows in the early 15th century, when small arms advanced from being hand-cannons capable of throwing a ball towards a mass of soldiers to something that could be aimed, shooting a lead ball at a higher velocity at a more specific target, A big part of that was the advance in manufacturing gunpowder, figuring out how to refine saltpeter, corn the powder, etc. The Hussite armies of the early 15th c. featured a mix of crossbowmen and shoulder arms. But it's not quite true that crossbows were displaced by shoulder arms as much as bowmen were found incapable of defending against the highly-mobile tactics of blocks of pikemen and halberdiers of the later 15th. c, innovated by the Swiss mercenaries. A pretty good marker for this development would be the Battle of Guinegate in 1479. After this, the battlefields of Europe tended to be dominated by pikemen, heavy cavalry ( like the French gendarmes) and artillery. Gradually arquebuses would be improved, becoming more portable and always equipped with matchlocks for firing, and arquebusiers would be used more and more effectively, through the Italian Wars, until finally at Pavia in 1525 arquesbuses would be shown to be indispensable.
However, crossbows for hunting continue to be made for quite some time, at least into the 18th c.