A DataGrid Control as a Disconnected Data Entry Tool | CodeGuru

A DataGrid Control as a Disconnected Data Entry Tool

Author: Lothar Haensler DataGrid Control as a Data-Entry Tool (VB6 – Maybe VB5) This sample was added after a superb response from the CodeGuru VB discussion forum. The original requirement was for a way of entering and modifying a list of data in a tabular format. Lothar suggested the use of a disconnected ADOR recordset […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 3, 2004
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Author: Lothar Haensler

DataGrid Control as a Data-Entry Tool (VB6 – Maybe VB5)

Screen Shot

This sample was added after a superb response from the CodeGuru VB discussion forum. The original requirement was for a way of entering and modifying a list of data in a tabular format. Lothar suggested the use of a disconnected ADOR recordset and the DataGrid control that comes with VB6 – a simple solution that works perfectly for the job.

Firstly, you need to set a reference to Microsoft Active Data Objects Recordset 2.1 library (msador15.dll). Then add the DataGrid component into your VB6 toolbar and paste in the following code into the Form_Load event after adding a Grid (DataGrid1) to your form:

private Sub Form_Load()
    Dim r as ADOR.Recordset
    Dim lCount as Long

'
' Create a new disconnected recordset object
'
    set r = new ADOR.Recordset
'
' Setup the fields - you can use any valid type of
' ado field type for these. I've used VarChar just
' for testing / demonstration purposes.
'
    r.Fields.Append "Name", adVarChar, 10
    r.Fields.Append "Notes", adVarChar, 50
    r.CursorType = adOpenDynamic
    r.Open
    r.AddNew

    r.Fields(0).Value = "Chris"
    r.Fields(1).Value = "almost over the hill"
    r.AddNew
    r.Fields(0).Value = "Chris"
    r.Fields(1).Value = "but enjoying every minute"

    for lCount = 1 to 25
        r.AddNew
        r.Fields(0).Value = "Name " & lCount + 2
        r.Fields(1).Value = "some kind of description"
    next
'
' Populate the datagrid
'
    set DataGrid1.DataSource = r

End Sub
'
'

The attached sample shows how to add new lines to the control ‘on-the-fly’ and also how to query the values in the grid using another ADOR Recordset object.

Download Zipped Project file (3k)

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.