Solved

VB Datagrid sort by column

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

Expert Comment

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

Author Comment

by:Lambdasensor
Comment Utility
I will give it a go - thanks!
0
 

Author Comment

by:Lambdasensor
Comment Utility
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 69

Accepted Solution

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

Author Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now