I have a toggle button that, when pressed, is supposed send the value ("parameter" field) of a list selection to a table (tblConsumed) it is also supposed to send the value of a textbox ("used_today" field). It also records the date. In VBA, the the following code works correctly:
Code:
DoCmd.RunSQL "insert into tblConsumed([day], parameter, used_today) values (date(), [Forms]![frmvettest]![lstParameter], [Forms]![frmvettest]![txtSlidesUsed]);"
I'm trying to get away from VBA though. I created a query, called qrySendSlide, in the query list in Access that looks like this (same as the VBA code):
Code:
INSERT INTO tblConsumed ( [day], parameter, used_today )
VALUES (date(), [forms]![frmVetTest]![lstParameter], [forms]![frmvettest]![txtslidesused]);
When the toggle button is pressed, this is the VBA code that I'd like to ideally use:
Code:
DoCmd.RunSQL "qrySendSlide"
When this code runs, however, I get the error: "Run-time error '3129': Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE','SELECT', or 'UPDATE'." (Even though I have the "insert" statement.)
I also tried making the query using the query design. After doing this, the SQL comes out to look like this:
Code:
INSERT INTO tblConsumed ( [day], Forms!frmvettest!lstParameter, Forms!frmvettest!txtSlidesUsed )
SELECT Date() AS Expr1, [Parameter] AS Expr2, [Used_Today] AS Expr3;
I get the same error with this code.
Also, the data types do match. Day: Date/Time, Parameter: Text, used_today: Number (integer). I left out the ID (Autonumber).
Is there a way for me to do this using a pre-written query in the query list outside of VBA, or do I need to write out that entire query in VBA.
Thank you,
Brad