Solved

Include ampersand in a string variable

Posted on 2004-04-16
7
672 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

762 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