Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2010, 09:34 PM
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default quotes within a Where string

I've got a 'comments' field that I'd like to filter by, if desired. Problem is many of the comments include commas, quotes and/or apostrophies as a part of the literal text.

I am adding the following code to a Where string.

What is the proper syntax to do what I want?


Code:
If [Forms]![frm_SpecificInfo]![Comments] <> "*" Then
WhereStr = WhereStr & " AND ((tbl_Data_Setinfo.comments) Like """ & [Forms]![frm_SpecificInfo]![Comments] & """) "
Else: End If
 
Old August 27th, 2010, 03:04 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

There are a couple of ways you can do this. I think what you want is anything containing the entry in the comment field of a form? Then it would be:

Code:
If [Forms]![frm_SpecificInfo]![Comments] <> "*" _
  Then WhereStr = WhereStr & " AND tbl_Data_Setinfo.comments Like ""*" _
  & [Forms]![frm_SpecificInfo]![Comments] & "*"" "
Without any wildcards a like works basically the same as =

Another way to do this is:

Code:
If [Forms]![frm_SpecificInfo]![Comments] <> "*" _
  Then WhereStr = WhereStr & " AND InStr(1,tbl_Data_Setinfo.comments,""" _
  & [Forms]![frm_SpecificInfo]![Comments] & """) > 0 "
Also I'd personally steer clear of using ! and start using . instead





Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Double Quotes from a string Durkee VB.NET 2002/2003 Basics 12 October 4th, 2007 12:10 PM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 02:17 PM
how to return string value with quotes (single or tllcll BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 November 10th, 2005 01:57 PM
Quotes in SQL String Retrieving Access Data ritag Access VBA 5 November 17th, 2004 06:04 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.