Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005
    Posts
    49

    Unanswered: Inserting "Microsoft" into a db, erroring out due to "

    Hello,

    I have...


    DoCmd.RunSQL "Update shiftsummary Set afternoon = ('" & txtafternoon & "') where day = [txtday]"

    In the txtafternoon field it has commas, quotations and more and it is erroring out the update. Anyone know anyways around this?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I tend not to use runsql that often but your sql statement looks mighty odd to me, I would tend to construct it something similar to this:-
    strSQL="Update shiftsummary Set afternoon = " & chr$(34) & txtafternoon & chr$(34) & " where day = [txtday]"

    is txtday a numeric field, if not then it to needs speech marks

    strSQL="Update shiftsummary Set afternoon = " & chr$(34) & txtafternoon & chr$(34) & " where day = " & chr$(34) & [txtday] & chr$(34)

    Then docmd.runsql strSQL. by buildingthe sql as a separate variable you can easily see what SQL you are actually presenting to the data engine - either with a msgbox bfore the docmd, of debug.print.

    BTW There is nothing magical about chr$(34) - its just an old habit I got into avoiding problems of the Access & VB IDE's inserting additional " characters.

Posting Permissions

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