Solved

VB Datagrid sort by column

Posted on 2003-11-10
5
1,298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

729 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