Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Include ampersand in a string variable

Posted on 2004-04-16
7
Medium Priority
?
819 Views
Last Modified: 2010-05-18
How can I include the ampersand character in a string variable?  I am using this variable in an INSERT INTO table statment and the string looks fine when sent to the Immediate window, however when the string is inserted into a table is is cutoff prior to the ampersand.

Thanks!!
0
Comment
Question by:silsuba
[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
7 Comments
 
LVL 51

Expert Comment

by:Steve Bink
ID: 10843501
My first thought is to change "&" to "&&".  Many apps use "&" to signify the beginning of a special character code.  For a more specific solution, please post your INSERT statement.
0
 
LVL 14

Expert Comment

by:JohnK813
ID: 10843511
chr(38) is the ASCII code for &

So, you'd say strMystring & chr(38)
0
 

Author Comment

by:silsuba
ID: 10843615
Here's the insert statment


INSERT INTO tblCompany (companyName,sectorID,marketID,submarketID,relationID,website,datestamp) VALUES ('" & strCompanyName & "','" & intSectorID & "'," & _
                "'" & intMarketID & "','" & intSubmarketID & "','" & intRelationID & "','" & strWeb & "','" & dteDate & "')

I assign this to the string variable mySQL, and when I print the string to the immediate window I get something like this...

INSERT INTO tblCompany (companyName,sectorID,marketID,submarketID,relationID,website,datestamp) VALUES ('University of Pennsylvania, School of Engineering & Applied Sciences','1','4','17','0','','4/16/2004')

Now when I execute mySQL everything is inserted into the table but the companyName stops prior to the "&", in the example above, University of Pennsylvania, School of Engineering is the only information inserted.  

I did try this using your suggestion JohnK

 mySQL = Replace(mySQL, "&", Chr(38))

but still did not insert correctly.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Accepted Solution

by:
Shailesh15 earned 200 total points
ID: 10843749
Just a thought ....Check your field Length.
0
 
LVL 6

Expert Comment

by:Plamodo
ID: 10843819
Just a thought.. instead of using single quotes around string values in your sql statement like this: '

.. Maybe use chr$(34) instead.

INSERT INTO tblCompany (companyName,sectorID,marketID,submarketID,relationID,website,datestamp) VALUES (chr$(34) & strCompanyName & chr$(34) & "','" & intSectorID & "','" & _
                "'" & intMarketID & "','" & intSubmarketID & "','" & intRelationID & "','" & strWeb & "','" & dteDate & "')
0
 

Author Comment

by:silsuba
ID: 10843947
I was looking in the wrong direction for the answer... thanks Shailesh15!!
0
 
LVL 14

Expert Comment

by:JohnK813
ID: 10844289
Shailesh15, that was my next thought... guess I picked a bad time to go to lunch!

silsuba, glad your question was answered.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

719 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