I have written code that will select a random sample from a table by assigning a random number to the data in a temporary table. this is all working fine until I try and use the following piece of code to create a new table and appending the top 50 records from the temporary tabel to it.
' Sort the data by the random number and move top 50 into a new table
strTableName = "tblRandom_" & Format(Date, "ddmmmyyyy")
strSql = "SELECT TOP 50 tblTemp.NINO,tblTemp.Surname,tblForename_1" & _
"INTO" & strTableName & " " & _
"FROM tblTemp " & _
"ORDER BY tblTemp.RandomNumber;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSql
DoCmd.SetWarnings True
I receive a Run Time error 2342 which states that a RunSQL action requires an argument consisting of an SQL statement.
I am unsure as to why this code does not work as any body got a solution to this problem.
Thanks
' Sort the data by the random number and move top 50 into a new table
strTableName = "tblRandom_" & Format(Date, "ddmmmyyyy")
strSql = "SELECT TOP 50 tblTemp.NINO,tblTemp.Surname,tblForename_1" & _
"INTO" & strTableName & " " & _
"FROM tblTemp " & _
"ORDER BY tblTemp.RandomNumber;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSql
DoCmd.SetWarnings True
I receive a Run Time error 2342 which states that a RunSQL action requires an argument consisting of an SQL statement.
I am unsure as to why this code does not work as any body got a solution to this problem.
Thanks