Solved

Include ampersand in a string variable

Posted on 2004-04-16
7
761 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

630 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