Consulting

Results 1 to 10 of 10

Thread: Solved: Insert Query Heip, [Code]

  1. #1
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location

    Solved: Insert Query Heip, [Code]

    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?

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

  2. #2
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by Trevor
    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?

    [vba]
    DoCmd.RunSQL = "Insert InTo [PSwrdAttemptTbl] (Status)" _
    & "Values (StStatus);"
    [/vba] 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);"

  3. #3
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    Quote Originally Posted by orange
    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

  4. #4
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    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

  5. #5
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    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.

  6. #6
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by Trevor
    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);"



    Should have been this:
    Try this
    DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
    & " Values (StStatus);"



    Note: The space before Values

  7. #7
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    [VBA]
    DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
    & " Values (StStatus);"
    [/VBA]
    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?

  8. #8
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by Trevor
    [vba]
    DoCmd.RunSQL "Insert InTo [PSwrdAttemptTbl] (Status)" _
    & " Values (StStatus);"
    [/vba] 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
    Last edited by orange; 03-25-2008 at 04:20 AM.

  9. #9
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    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

  10. #10
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •