ACC97: How to Use Percent, Plus, and Caret Symbols in ASP Forms

Last reviewed: November 10, 1997
Article ID: Q163334
The information in this article applies to:
  • Microsoft Access 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

When you use an Active Server Pages (ASP) form to add or modify data in a Microsoft Access database, if you type the percent (%), plus (+) or caret (^) symbols on the form, those characters may not translate correctly in the database. This article discusses how to modify your ASP form to enable you to use those characters.

NOTE: This article contains information about editing ASP files. The information is provided as is. Microsoft Access Technical Support Engineers do not support customizing your ASP files.

MORE INFORMATION

When you enter data in an ASP form and commit it, some special characters are interpreted at the Web server as part of the VBScript code that executes in the ASP file. When this happens, you may not see the correct characters in your database because the server tries to intercept them and process them. If you want to commit those characters to your database as their keyboard equivalents, you must create a function in the ASP file that translates them into their hexadecimal escape sequences.

When Microsoft Access 97 creates ASP files, it automatically creates a VBScript function in the file that translates most special characters back to their keyboard equivalents, such as the number sign (#) and the ampersand (&). If you want to use percent, plus or caret symbols, you must modify the translation function to include those characters as well.

Each form that you export to ASP format creates at least two files: <FormName>.asp and <FormName>alx.asp. The "alx" file contains the translation function you need to modify. The following example shows you how to create and modify an ASP file to accept the percent, plus and caret symbols.

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Select the Customers form in the Database window.

  3. On the File menu, click Save As/Export.

  4. In the Save As dialog box, click "To an External File or Database," and then click OK.

  5. In the "Save Form 'Customers' In" dialog box, select Microsoft Active Server Pages (*.asp) in the Save As Type box, and select a folder on your Web server where you have Execute permission in the Save In box. Click Export.

  6. In the Microsoft Active Server Pages Output Options dialog box, type the name of a System DSN on your Web server that connects to the Northwind sample database in the Data Source Name box, and type the uniform resource locator (URL) for the folder on your server where the ASP forms will reside in the Server URL box. Click OK.

    Two files will be created on your Web server computer: Customers.asp and Customersalx.asp.

  7. Use a text editor, such as Notepad, to open the Customersalx.asp form on your Web server.

  8. Locate the MakeHTMLValue function in the file, which looks as follows:

          Function MakeHTMLValue(szVal)
    
             Dim i
             Dim szRet
             for i = 1 to Len(szVal)
                ch = Mid(szVal, i, 1)
                if ch = " " Then
                   szRet = szRet & "%20"
                elseif ch = "&" Then
                   szRet = szRet & "%26"
                elseif ch = "#" Then
                   szRet = szRet & "%23"
                elseif ch = """" Then
                   szRet = szRet & "%22"
                elseif ch = ";" Then
                   szRet = szRet & "%3B"
                elseif ch = ":" Then
                   szRet = szRet & "%3A"
                elseif ch = "'" Then
                   szRet = szRet & "%27"
                else
                   szRet = szRet & Mid(szVal, i, 1)
                end if
             next
          MakeHTMLValue = szRet
       End Function
    
    

  9. Modify the MakeHTMLValue function to include the escape sequences for the percent, plus, and caret symbols so that it looks as follows:

          Function MakeHTMLValue(szVal)
    
             Dim i
             Dim szRet
             for i = 1 to Len(szVal)
                ch = Mid(szVal, i, 1)
                if ch = " " Then
                   szRet = szRet & "%20"
                elseif ch = "&" Then
                   szRet = szRet & "%26"
                elseif ch = "#" Then
                   szRet = szRet & "%23"
                elseif ch = """" Then
                   szRet = szRet & "%22"
                elseif ch = ";" Then
                   szRet = szRet & "%3B"
                elseif ch = ":" Then
                   szRet = szRet & "%3A"
                elseif ch = "'" Then
                   szRet = szRet & "%27"
                elseif ch = "%" Then
                   szRet = szRet & "%25"
                elseif ch = "+" Then
                   szRet = szRet & "%2B"
                elseif ch = "^" Then
                   szRet = szRet & "%5E"
                else
                   szRet = szRet & Mid(szVal, i, 1)
                end if
             next
          MakeHTMLValue = szRet
       End Function
    
    

  10. Save the Customersalx.asp file and close it.

When you open Customers.asp in your Web program, you will be able to use percent, plus, or caret symbols in the text boxes on the form in the Company Name field for example, and those characters will appear correctly in the Customers table of the Northwind database.


Additional query words: reserved map xlate
Keywords : kbinterop IntAsp
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.