Solved

VB Datagrid sort by column

Posted on 2003-11-10
5
1,286 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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