Results 1 to 4 of 4
  1. #1
    Swarland is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Location
    Northumberland, UK
    Posts
    16

    RunSQL String Problem

    I am trying to use the DoCmd.RunSQL command to add a new record to an existing table. The code is attached to a button and is as follows:



    strSQL = "INSERT INTO RoomItemDetails (Roomref, QuoRef, ProductItemRef, Ordered) VALUES (intRoomid, [Quote Ref], '5', true)"

    DoCmd.RunSQL strSQL

    In VALUES, intRoomID is a declared integer variable holding an integer value; [Quote Ref] is a field known to this form; '5' is a string and true is a boolean Y/N state.

    The programme doesn't seem to like the variable intRoomID, as it puts up a message box asking for it, but works as planned when this is given. I have tested that the variable gets the number; I populate the variable by using the output from a recordset of a table using rstTable(0): I have also tried using this in the Values section instead of intRoomID, but it thinks it is an undeclared function.

    Has anyone any ideas please?

    regards

    Roger

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you need to makeup a pure SQL string like this:
    strSQL = "INSERT INTO RoomItemDetails (Roomref, QuoRef, ProductItemRef, Ordered) VALUES ( '" & intRoomid & "', '" & [Quote Ref] & "', '5', true)"

  3. #3
    Swarland is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Location
    Northumberland, UK
    Posts
    16
    Many thanks for the info - it works as requested. Another big smile

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I like smiles

Please reply to this thread with any new information or opinions.

Similar Threads

  1. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  2. docmd.runsql update
    By Mitch_Aus in forum Programming
    Replies: 2
    Last Post: 10-05-2010, 09:45 AM
  3. Problem with building SQL string (VBA)
    By cdpeck in forum Programming
    Replies: 1
    Last Post: 09-15-2009, 04:25 AM
  4. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  5. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums