RunSQL

KevW

Registered User.
Local time
Today, 10:59
Joined
Nov 11, 2005
Messages
41
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
 
This is just a guess, based on a similar problem I had a little while back, but you don't appear to have a space between "tblForename_1" and "INTO", or between "INTO" and strTableName.

Could that be causing it?
 

Users who are viewing this thread

Back
Top Bottom