Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


VBA syntax question

Posted on 2004-03-30
Medium Priority
Last Modified: 2012-06-21
I have a search form that returns values in a subform.  I recently added a field to this search form, but there is a problem.  Below is the code that applies the LIKE statement to the querydef:

If Not IsNull(Me.VendItem) Then
strWhere = strWhere & "(itemvend1.[vend-item]) Like '*" & Me.VendItem & "*' AND "
End If

If VendItem contains "#", the search will come up null.  The SQL works fine, I am sure it is a syntax issue.  Could someone assist me with this?

Thanks.  Please let me know if you have any questions.

Question by:iptrader
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 10715725
BTW, I have tried different variations of the syntax and have come up empty :)
LVL 10

Expert Comment

ID: 10715876
try replacing # with % ?


Author Comment

ID: 10715883
John, the field name is set in the table.  I am pulling it in the dropdown box directly with SELECT DISTINCT string.


Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

LVL 32

Accepted Solution

jadedata earned 800 total points
ID: 10715889
Greetings iptrader!

 The "#" may be being interpreted as a date delimiter in the context of the sql string when IT is evaluated.
 What are these symbols doing in the data?

this uses embedded double quotes to "wrap" the venditem return string
  strWhere = strWhere & "(itemvend1.[vend-item]) Like " & chr(34) & "*" & Me.VendItem & "*" & chr(34) &" AND "

this removes the "#" from both strings prior to comparison.... (works for AccXP & Up)
  strWhere = strWhere & "(Replace([itemvend1].[vend-item],'#','') Like " & chr(34) & "*" & Replace(Me.VendItem,"#","") & "*" & chr(34) &" AND "


Author Comment

ID: 10715907
Hi jack,

Unfortunately a lot of our users are on Access2K.

Any tips?



Author Comment

ID: 10715915
Jack, also, the data is legacy data.  Nothing can be done about that.  Sorry.

LVL 51

Expert Comment

by:Steve Bink
ID: 11945912
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:


Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question