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

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

Article ID:163334
Last Review:November 4, 2003
Revision:1.0
This article was previously published under Q163334
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

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 Product Support Professionals 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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值