Solved

How do I read a field with an & in it for SQL

Posted on 2014-10-30
5
91 Views
Last Modified: 2014-11-04
Hello Everyone,

I have an access 2010 program that I am converting to work with the backend on the cloud.  On one form I have a listbox that when the user clicks on a line the system needs to find the record based on a client ID and client name.  Sadly some of the client names have & in them.  I am getting a parsing error because of the &.

Short of changing the & to and for all the clients is there a way using VBA to have it see the & as an &?

Thanks
0
Comment
Question by:alevin16
  • 3
5 Comments
 
LVL 14

Expert Comment

by:ThomasMcA2
ID: 40414448
Try putting the field name in quotes.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40414500
If you mean you are using SQL strings to query your backend try...

SELECT * from tblCompanies WHERE tnlCompanies.CompanyName like 'Benson \& Sons';

You need to replace all & with \& before your selects.
0
 

Accepted Solution

by:
alevin16 earned 0 total points
ID: 40414620
Hello All

Here is a snippet of the code.  on line 120 is where I put the value into a field.  Is there something I could do to the field in the text box?


120       cmd.Parameters("@txtemployeescompany").Value = [Forms]![MainForm2].[Form]![frmCurrent]![txtEmployeesCompany]
         
130       Set rst = cmd.Execute

140       If Not rst.EOF Then
150           Set rstClone = ut_MakeRS(rst)
160           ut_OpenAndFillRS rst, rstClone
0
 

Author Comment

by:alevin16
ID: 40414850
Hello everyone,

I found my error.  It was actually not a & but a / in the name.  In my program those are easy to remove and keep the people from putting them in again.

Thank you all!
0
 

Author Closing Comment

by:alevin16
ID: 40421164
I asked the wrong question actually
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now