Solved

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

Posted on 2014-10-30
5
93 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
[X]
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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

726 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