Solved

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

Posted on 2014-10-30
5
89 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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

10 Experts available now in Live!

Get 1:1 Help Now