Solved

Include ampersand in a string variable

Posted on 2004-04-16
7
651 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
7 Comments
 
LVL 50

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 10

Accepted Solution

by:
Shailesh15 earned 50 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

792 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