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
Solved

Need help formatting a string from a text box

Posted on 2011-09-08
7
188 Views
Last Modified: 2012-05-12
I have a form which displays the name of the Holiday and I wish to use that name to update a field in another field in another table.  However the way that I have written my code it errors out on the fact that there are spaces in the name of the Holiday, such as "Washingons Birthday" or "Fourth of July".  It would not be a problem if it stripped out the spaces and inserted the name without the spaces but I am not sure of the function to call to do that.  I am using Access 2007 in an ADP format and this is only part of the query.  I have been able to get it functional to this point.

Where it is failing is when I reference Left([Forms]![Holiday]![Holiday],25)
strSQL = " Update AdjustedSchedule"
    strSQL = strSQL & " Set AdjustedSchedule.HOLADJUST =" & [Forms]![HOLIDAY]![DOW] & ","
    strSQL = strSQL & " AdjustedSchedule.HOLIDAY =" & Left([Forms]![HOLIDAY]![HOLIDAY], 25) & ","
    strSQL = strSQL & " AdjustedSchedule.STATUS = 'Holiday';"
    DoCmd.RunSQL (strSQL)

Open in new window

0
Comment
Question by:JasBrad
  • 3
  • 2
  • 2
7 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 36505243
You need to enclose the values in single quotes, just as you have for the STATUS field.
0
 
LVL 33

Accepted Solution

by:
Norie earned 65 total points
ID: 36505256
Oops, forgot the code.

strSQL = " Update AdjustedSchedule"    
strSQL = strSQL & " Set AdjustedSchedule.HOLADJUST ='" & [Forms]![HOLIDAY]![DOW] & "',"    
strSQL = strSQL & " AdjustedSchedule.HOLIDAY ='" & Left([Forms]![HOLIDAY]![HOLIDAY], 25) & "',"   
strSQL = strSQL & " AdjustedSchedule.STATUS = 'Holiday';"    DoCmd.RunSQL (strSQL)

Open in new window

0
 
LVL 9

Assisted Solution

by:borki
borki earned 60 total points
ID: 36505265
I think you are missing the string delimiters. Try

strSQL = " Update AdjustedSchedule"
    strSQL = strSQL & " Set AdjustedSchedule.HOLADJUST =" & [Forms]![HOLIDAY]![DOW] & ","
    strSQL = strSQL & " AdjustedSchedule.HOLIDAY = '" & Left([Forms]![HOLIDAY]![HOLIDAY], 25) & "',"
    strSQL = strSQL & " AdjustedSchedule.STATUS = 'Holiday';"
    DoCmd.RunSQL (strSQL)

0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:JasBrad
ID: 36505373
That worked but one other question.  How do I get it to ignore apostrophes in the name? or is that not possible?
0
 
LVL 9

Expert Comment

by:borki
ID: 36505446
You would need to parse the string before hand and replace any instance of a single apostrophe with two apostrophes, eg

replace(string, "'", "''")

or

Left(Replace([Forms]![HOLIDAY]![HOLIDAY], "'", "''"), 25)

Very hard to read ;-)
0
 
LVL 33

Expert Comment

by:Norie
ID: 36505507
borki

You can always use Chr(39).

Replace(string, Chr(39), Chr(39) & Chr(39))

Open in new window

Or, if you are using it a lot declare a constant.
Const SQ = "'"  ' Single Quote

Open in new window

Still quite messy though.:)
0
 

Author Comment

by:JasBrad
ID: 36505577
Thanks!!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

840 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