ACC97: How to Create Custom Navigation Buttons on an ASP Page (165629)



The information in this article applies to:

  • Microsoft Access 97

This article was previously published under Q165629
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

When you export a form from Microsoft Access 97 as an Active Server Page, and that form has custom buttons that move from one record to the next, the buttons will not work on your Active Server Page form. This happens because the Visual Basic code that performs the actions in Microsoft Access is not exported to your Active Server Page form.

There are two ways to have navigation buttons appear on your Active Server Page form:
  • Use the Microsoft Access built-in navigation buttons and set the Navigation property of the form to Yes.
  • Modify the VBScript for the Active Server Page form that you are exporting so that the code will allow you to move through your form as you click a button.

MORE INFORMATION

NOTE: This section contains information about editing ASP files and assumes that you are familiar with editing HTML files, Active Server Pages, and Visual Basic Scripting. Microsoft Access Product Support professionals do not support customization of any HTML, HTX, IDC, or ASP files.

This article demonstrates a method that creates custom navigation buttons that enable you to move through the form by modifying the VBScript for the Active Server Page file. To modify the VBScript for a particular form, follow these steps:
  1. Create the form that you will be using as an Active Server Page and add the following command buttons to the form:
       Command Button:
          Name: MoveNextRecord
          Caption: MoveNextRecord
    
       Command button:
          Name: MoveFirstRecord
          Caption: MoveFirstRecord
    
       Command button:
          Name: MoveLastRecord
          Caption: MoveLastRecord
    					
  2. Set the Navigation property of the Form to No.
  3. Export the form to Active Server Page format and note the folder to which the file is exported. There should be two files in this folder that are associated with your Active Server Page. One of the files will contain the characters "alx" (without the quotation marks).
  4. Use Notepad or another text editor to open the file that contains the characters "alx." You should see code similar to the following:
          <SCRIPT LANGUAGE=VBScript>
          <!--
          Dim rgszCtrls(6,2)
          Dim cMaxCtrls
          cMaxCtrls = 6
    
          Sub AddCtrlToList(szCtrl, szCtrlSrc)
              Dim i
              for i = 1 to cMaxCtrls
                  if rgszCtrls(i, 1) = szCtrl Then Exit Sub
                  if rgszCtrls(i, 1) = "" Then
                      rgszCtrls(i, 1) = szCtrl
                      rgszCtrls(i, 2) = szCtrlSrc
                      Exit Sub
                   End If
               next
           End Sub
    					
  5. Add the following three Sub procedures to the code just before the line that reads </SCRIPT>.

    NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.
          Sub FirstRecord_MoveFirstRecord_Click()
    
              Window.Location.Href =
                  "/scripts/formname.asp?nav_btn=nav_btn_MoveFirstRecord&" _
              & GetCtrlQueryString()
    
          End Sub
    
          Sub NextRecord_MoveNextRecord_Click()
    
              Window.Location.Href =
                  "/scripts/formname.asp?nav_btn=nav_btn__MoveNextRecord&" _
              & GetCtrlQueryString()
    
          End Sub
    
          Sub LastRecord_MoveLastRecord_Click()
    
              Window.Location.Href =
              "/scripts/formname.asp?nav_btn=nav_btn__MoveLastRecord&" _
              & GetCtrlQueryString()
    
          End Sub
    					
  6. Modify the OBJECT ID's for the above controls in the </SCRIPT> section and replace the names as follows:
           FirstRecord = FirstRecord_MoveFirstRecord.
           NextRecord = NextRecord_MoveNextRecord.
           LastRecord = LastRecord_MoveLastRecord.
    					
  7. Close and save the file.
  8. Open your Web browser and your Active Server Page form. Click one of the custom command buttons. The buttons should now enable you to move through the pages.

REFERENCES

For more information about what can be exported to ASP format, search the Help Index for "ASP files," and then view the topic "Using Supported and unsupported form controls for dynamic ASP format," or ask the Microsoft Access 97 Office Assistant.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbinterop kbProgramming KB165629