PDA

View Full Version : Solved: Insert Query Heip, [Code]



Trevor
03-24-2008, 10:21 AM
I have an insert query which is suposse to insert the value of stStatus(string) Into table pSWrdAteemptTbl, colum [status]
And when I try to run it (onclick) I get "Argument not optional" and highlghts DoCmd.RunSQL, isn't Inert an action so i can use DOCmd.RunSQL?


DoCmd.RunSQL = "Insert InTo [PSwrdAttemptTbl] (Status)" _
& "Values (StStatus);"

If I can't run DoCmdRunSQL, are my only options to create a query to pass the value or pass though a textbox?

orange
03-24-2008, 12:42 PM
I have an insert query which is suposse to insert the value of stStatus(string) Into table pSWrdAteemptTbl, colum [status]
And when I try to run it (onclick) I get "Argument not optional" and highlghts DoCmd.RunSQL, isn't Inert an action so i can use DOCmd.RunSQL?


DoCmd.RunSQL = "Insert InTo [PSwrdAttemptTbl] (Status)" _
& "Values (StStatus);"
If I can't run DoCmdRunSQL, are my only options to create a query to pass the value or pass though a textbox?
Try this
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& "Values (StStatus);"

akn112
03-24-2008, 12:47 PM
Try this
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& "Values (StStatus);"

missing a space after your first end quote :)

Trevor- Doing lots of SQL i see. It's a good/frustrating experience

Trevor
03-24-2008, 03:41 PM
Thanks, it somewhat works, When I run the code I get a query popup box asking for the value I want to insert into status field of the table but the value is in ststaus(achieved by a dlookup), I even placed the sql string directly under my strstatus dlookup and still get the same resules.
I tested this by when the query popup box came up I enterd bbb, and looked at the table and the field now containd bbb

Trevor
03-24-2008, 03:43 PM
akn112 I stil had my original inert query just commented out and I check the space after the first end quote before the underscore and there was 1 space there, so I can't see what Orange did differently.

orange
03-24-2008, 05:18 PM
akn112 I stil had my original inert query just commented out and I check the space after the first end quote before the underscore and there was 1 space there, so I can't see what Orange did differently.
Trevor,

What akn112 was saying is that

Try this
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& "Values (StStatus);"
http://www.vbaexpress.com/forum/images/quotes/quot-bot-left.gif

Should have been this:
Try this
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& " Values (StStatus);"
http://www.vbaexpress.com/forum/images/quotes/quot-bot-left.gif

Note: The space before Values

Trevor
03-24-2008, 06:01 PM
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& " Values (StStatus);"

I get a popup query window asking for the peramiters of ststatus, whan ststaus is the reulting value of DLookup, I have tested ststaus by assinging the value of ststus to a text box to varify it has a value and it does, so I don't know why its asking for permaiters or what else is wrong with the inert query?

orange
03-24-2008, 10:22 PM
DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
& " Values (StStatus);"
I get a popup query window asking for the peramiters of ststatus, whan ststaus is the reulting value of DLookup, I have tested ststaus by assinging the value of ststus to a text box to varify it has a value and it does, so I don't know why its asking for permaiters or what else is wrong with the inert query?
You will have to build this up in VBA. The RunSQL will not understand StStatus in this form.

You could build something like
sSQL = "Insert InTo [PSwrdAttemptTbl] (Status)" _
& " Values ( '" & myParm & "')"
Then
docmd.runsql ssql

Trevor
03-25-2008, 07:17 AM
thanks orange, its early for me but don't I need to decaire myparm = stStatus then use my SQL statement (it's early, forgive me if I ask a dumb question

Trevor
03-25-2008, 12:05 PM
my last queston is realy without thinking after apply what I posted
all I did was sub the & myparm & for & ststatus &
and it worked, thanks