Soviet troops occupied Latvia on 17 June 1940. On 14 July 1940 ‘elections’ were held, but not really free: the soviet press association came too early with the results and 24 hour before closing the ballot-boxes the election results are published in a Londen newspaper.
The LPSR – short for Latvijas Padomju Sociālistiskā Republika (Latvian Soviet Socialist Republic)- is established on 21 July. This Republic is incorporated in the Soviet Union on 5 August 1940 as 15th republic of the USSR. On 22 June 1941 start the war between Germany and Russia. Riga is occupied by Germany on 1 July.
More about the LPSR in Wikipedia.