Chris Chevalier
Chris Chevalier

Reputation: 650

How do I fix the 424 runtime error "Object Required" in MS-Access from my VBA code

When running my VBA code in access I get the runtime error 424, "Object Required". This Is the code causing the error (specifically line 2)

 DoCmd.RunSQL "DELETE * From PF_PC_TOTAL; "
 DmCmd.RunSQL "INSERT INTO Table![PF_PC_TOTAL] VALUES ('Andre', 5, 6 ) ;"

Upvotes: 0

Views: 2497

Answers (2)

GuitarPicker
GuitarPicker

Reputation: 316

Omit the "Table!" prefix from your table name. The "bang" notation is only recognized by VBA code, not the SQL engine that your VBA code is using.

DmCmd.RunSQL "INSERT INTO [PF_PC_TOTAL] VALUES ('Andre', 5, 6 ) ;"

There is another question which explains that part in more detail and has some good links: Bang Notation and Dot Notation in VBA and MS-Access

You may also want to check the code samples in the documentation: https://msdn.microsoft.com/en-us/library/office/ff834799.aspx

They are using the .Execute method of the Database object, but the SQL syntax is the same for DoCmd.RunSQL.

Upvotes: 0

Saagar Elias Jacky
Saagar Elias Jacky

Reputation: 2688

Try this

DmCmd.RunSQL "INSERT INTO PF_PC_TOTAL (COL1, COL2, COL3) VALUES ('Andre', 5, 6 ) ;"

and replace COL1, COL2 and COL3 with actual column names in the table

Upvotes: 2

Related Questions