HOWTO: Create an HTML Page Using ADO and MSFlexGrid

ID: Q186287

The information in this article applies to:

SUMMARY

This article describes how to create a Web page that combines the MSFlexGrid control with ActiveX Data Objects (ADO).

MORE INFORMATION

Below is an HTML example that uses the MSFlexGrid control with ActiveX Data Objects (ADO) to produce a Web page from a database stored on the client machine. The project shows the use of the GetString function, which is new to Visual Basic 6.0.

NOTE: This code work correctly only on machines with Visual Basic 6.0 installed; it does not work on a machine with Visual Basic 5.0 installed.

Although this example uses a local reference to the database, the reference could point to a remote database's directory, and the server's name can be changed to reflect a remote machine name.

Step-by-Step Procedure

1. Start an instance of Notepad.

2. Cut and paste the code below into the instance of Notepad

3. Edit the connection string to match your machine.

4. Save the file as MyADOpage.html.

5. Double-click the newly saved file to invoke IE and the Web page.

You can also use the ActiveX control pad to add additional ActiveX controls to the project for additional functionality:

   <HTML>
   <HEAD>
   <TITLE>New Page</TITLE>
   </HEAD>
   <BODY>
   <OBJECT ID="MSFlexGrid1" WIDTH=787 HEIGHT=159
   CLASSID="CLSID:6262D3A0-531B-11CF-91F6-C2863C385E30">
   <PARAM NAME="_ExtentX" VALUE="20796">
   <PARAM NAME="_ExtentY" VALUE="4207">
   <PARAM NAME="_Version" VALUE="393216">
   <PARAM NAME="AllowUserResizing" VALUE="1">
   </OBJECT>

   <SCRIPT LANGUAGE = "VBSCRIPT">

   Sub Window_OnLoad()
   Dim MyCon
   Dim ADC
   Set MyCon = CreateObject("ADODB.Connection")
   Set ADC = CREATEOBJECT("ADODB.RECORDSET")

   MyCon.Open "Driver={Microsoft Access Driver (*.mdb)};Server=Machine
   Name;dbq=C:\Program Files\Microsoft Visual Studio\vb98\NWind.mdb"

   ADC.Open "SELECT * FROM PRODUCTS", MyCon, , , adOpenKeyset

   MSFlexGrid1.Cols = ADC.Fields.Count + 1

   Dim V

   Do While Not ADC.EOF
      V = V + 1
   ADC.MoveNext
   Loop

   ADC.MoveFirst
   MSFlexGrid1.Rows = V + 1
   MSFlexGrid1.Row = 0
   MSFlexGrid1.Col = 1
   ADC.MoveFirst
   Dim MyResource
   MyResource = ADC.GetString

   MsFlexGrid1.Cols = ADC.Fields.Count
      For X = 0 To ADC.Fields.Count - 1
          MSFlexGrid1.TextMatrix(0, X) = ADC.Fields(X).Name
      Next
      MSFLEXGRID1.Row = 1
      MSFLEXGRID1.Col = 0
      MSFLEXGRID1.RowSel = MSFLEXGRID1.Rows - 1
      MSFLEXGRID1.ColSel = MSFLEXGRID1.Cols - 1
      MSFLEXGRID1.Clip = MyResource
      MSFLEXGRID1.RowSel = MSFLEXGRID1.Row
      MSFLEXGRID1.ColSel = MSFLEXGRID1.Col

   End Sub
   </SCRIPT>
   </BODY>
   </HTML>

REFERENCES

For more information about ADO, use the Visual Basic Help. Query on ADO, DHTML, and/or MSFlexGrid.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Richard T. Edwards, Microsoft Corporation

Additional query words: kbdse kbDSupport kbVBp kbADO kbActiveX kbVBp600 kbHTML

Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: August 27, 1998