Solved

VB Datagrid sort by column

Posted on 2003-11-10
5
1,288 Views
Last Modified: 2013-12-26
I have an adodc which connects to an access database and a record source of a query in access.
The datagrid connects to the adodc and displays the query.

What I want to do is when a user clicks on the column headings the datagrid sorts into alphabetical order.

I found this code on another post:

Private Sub DataGrid1_HeadClick(ByVal ColIndex _
     As Integer)
Dim sortField As String
Dim sortString As String

sortField = DataGrid1.Columns(ColIndex).Caption
If InStr(rst.Sort, "Asc") Then
     sortString = sortField & " Desc"
Else
     sortString = sortField & " Asc"
End If
rst.Sort = sortString
End Sub

but when I run it I get a run time error object required on the line
If InStr(rst.Sort, "Asc") Then

Could someone please suggest a step by step solution
to this problem?
0
Comment
Question by:Lambdasensor
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9714517
Everywhere you see rst, you need to replace it with the name of your adodc like this: adodc1.recordset
0
 

Author Comment

by:Lambdasensor
ID: 9714756
I will give it a go - thanks!
0
 

Author Comment

by:Lambdasensor
ID: 9714765
Method or data member not found when it gets to .Sort

Private Sub DataGrid1_HeadClick(ByVal ColIndex _
     As Integer)
Dim sortField As String
Dim sortString As String

sortField = DataGrid1.Columns(ColIndex).Caption
If InStr(Adodc1.Sort, "Asc") Then
     sortString = sortField & " Desc"
Else
     sortString = sortField & " Asc"
End If
Adodc1.Sort = sortString
End Sub
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 9714979
you also need to specify the Recordset object: adodc1.recordset.sort
0
 

Author Comment

by:Lambdasensor
ID: 9716028
Yes it works, very happy now :) Thanks for your help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

856 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