Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help formatting a string from a text box

Posted on 2011-09-08
7
Medium Priority
?
194 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 35

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 35

Accepted Solution

by:
Norie earned 260 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 240 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 35

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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 …

971 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