?
Solved

VB Datagrid sort by column

Posted on 2003-11-10
5
Medium Priority
?
1,311 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 200 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

Industry Leaders: 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

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 …
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…
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…
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…
Suggested Courses

770 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