Solved

Datagrid Control - Error: The current row is not available

Posted on 2004-04-29
1
1,166 Views
Last Modified: 2013-12-25
Hello,
       I have a couple of questions....
       1) I am using a Datagrid Control which is populated from a database. When i close the form i get an Error - "The current row is not available". The datagrid control is not editable. When i debug through the form, i do not get this error or when the entire row is selected.
       2) I want to be able to select an entire row when clicking on any field. Is this possible?

Thank you for your help.
0
Comment
Question by:ppseeth
1 Comment
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 10955751
1) http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20749316.html

2) Here is the required code for that:

Option Explicit

Dim rstX As ADODB.Recordset

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    With DataGrid1
        ' Remove previously saved bookmark from collection
        If .SelBookmarks.Count <> 0 Then .SelBookmarks.Remove 0
        ' Append your bookmark to the collection of selected rows
        If Not IsNull(.Bookmark) Then .SelBookmarks.Add .Bookmark
    End With
End Sub

Private Sub Form_Load()
Dim colX As Variant

    Set rstX = New ADODB.Recordset
    rstX.CursorLocation = adUseClient
    rstX.Open "Select * from Employees", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Projets VB\NWIND.MDB;Persist Security Info=False", adOpenStatic, adLockReadOnly
    Set DataGrid1.DataSource = rstX
    DataGrid1.Refresh
    For Each colX In DataGrid1.Columns
        colX.Locked = True
    Next
End Sub

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now