Results 1 to 4 of 4
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    opening form code where the name contains an apostrophe

    This code works fine unless the stadium name contains an apostophe. I have so far been less than successful in adding a "wild card (*)".

    Code:
    DoCmd.OpenForm "ProStadiumListF", acNormal, , "[Stadium]=" & "'" & [Stadium] & "'"
    Any help would be appreciated.



    Thanks
    Jim O

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    One way is to escape the embedded apostrophe by doubling it in the parameter.

    DoCmd.OpenForm "ProStadiumListF", acNormal, , "[Stadium]='" & Replace([Stadium], "'", "''") & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thanks much that get the job done.

    Jim O

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Another approach is to use doubled quotes instead of apostrophe:

    DoCmd.OpenForm "ProStadiumListF", acNormal, , "[Stadium]=""" & [Stadium] & """"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Error in code while opening with ms access
    By sukhjinder in forum Programming
    Replies: 2
    Last Post: 09-27-2017, 12:50 PM
  2. Replies: 5
    Last Post: 01-24-2015, 12:59 AM
  3. Replies: 20
    Last Post: 07-07-2014, 03:04 PM
  4. Replies: 4
    Last Post: 12-13-2013, 04:50 PM
  5. Replies: 11
    Last Post: 07-24-2013, 11:49 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