I am having trouble with the following VBA statement:
The primary key of the target table is an autonumber field, TSH_ID (not PersonID!). When I execute the SQL I get the debug.print
and the error message 3061, "Too few parameters. Expected 3".
A couple of earlier posts on this forum seem to suggest that this is the correct way to do it. The Access Help (docs.microsoft .com) says "If you append records to a table with an AutoNumber field and you want to renumber the appended records, do not include the AutoNumber field in your query. Do include the AutoNumber field in the query if you want to retain the original values from the field.". (I'm not sure what that means: There wouldn't be an original number for a record that I'm just adding).
I built a query manually to do this, and it worked when run from the main window. The SQL it generated was
. However when I tried to put this into my VBA (with or without the "AS Expr" phrases) it also failed with the Too few parameters message.
Code:
strSQL = "INSERT INTO Walk_participation_history " _
& "(PersonID, WalkNumber, WalkDate, Posn_ID) " _
& "SELECT (Me!Person_ID, Me!cboPilgrimWalk, Walk_Date, 0);"
Set dbs = CurrentDb
dbs.Execute strSQL
Set dbs = Nothing
Code:
INSERT INTO Walk_participation_history (PersonID, WalkNumber, WalkDate, Posn_ID) VALUES (Me!Person_ID, Me!cboPilgrimWalk, Walk_Date, 0);
A couple of earlier posts on this forum seem to suggest that this is the correct way to do it. The Access Help (docs.microsoft .com) says "If you append records to a table with an AutoNumber field and you want to renumber the appended records, do not include the AutoNumber field in your query. Do include the AutoNumber field in the query if you want to retain the original values from the field.". (I'm not sure what that means: There wouldn't be an original number for a record that I'm just adding).
I built a query manually to do this, and it worked when run from the main window. The SQL it generated was
Code:
INSERT INTO Walk_participation_history ( PersonID, WalkNumber, WalkDate, Posn_ID ) SELECT 22 AS Expr1, "GC100" AS Expr2, #10/18/2007# AS Expr3, 0 AS Expr4;
Comment