Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Load a Form so that the DataGrid on it Will Sort by Two Fields 2

Status
Not open for further replies.

Hiccup

Programmer
Jan 15, 2003
266
0
0
US
My setup is VB6/Access2K. When loading a Form, I'm using this code:

Private Sub Command15_Click(Index As Integer)
Me.MousePointer = 11
Load DbDepForm
DbDepForm.Show
Unload Rent_Deposits_Menu
Me.MousePointer = 0
End Sub

The Form has a DataGrid1 and an Adodc1 connected to the Access mdb Table.

Is there a way to add code to the above so that when the Form with the DataGrid1 displays, the DataGrid1 will be sorted first by the DepDate field and then a second sorting by UnitNo? I thought possibly a SQL Select Group By statement in the above code, but I'm not sure how to set it up.

Thanks in advance.
 
On the property of your ADODC,

RecordSource
Type Command = adCmdText
Text Command = select * from your_table order by DepDate, UnitNo;
 
reneford...In the properties of the Adodc I have SortRentDeposits as the RecordSource, which is a sort query of the Access Deposits Table. I have DepDate checked to sort ascending in the Access query, but I need the Table further sorted by the UnitNo under the dates. Something like this should result:

DepDate UnitNo
1/1/05 100
1/1/05 101
1/1/05 102
1/15/05 100
1/15/05 101
etc. etc.

I tried to set this up in the Access Table by checking the DepDate as sorted and then the UnitNo as sorted next, but it didn't work. It only sorts the dates and the UnitNo are all mixed up.

That's why I was asking if it could be done with code in VB.

Thanks!
 
I want the same thing as you (with other data, of course)

DepDate UnitNo
1/1/05 100
1/1/05 101
1/1/05 102
1/15/05 100
1/15/05 101
etc. etc.

And I did what I explain to you and it's works for me.
Sorry, I don't understand what you want more...

Good Luck!


 
I tried to set this up in the Access Table by checking the DepDate as sorted
Change to SQL View in Access and change the order by clause as reneford said.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
reneford...guess I'm not sure where you're saying to pu the:

RecordSource
Type Command = adCmdText
Text Command = select * from your_table order by DepDate, UnitNo;

I tried this in a Form Load code, but it didn't work:

Private Sub Form_Load()
RecordSource
Type Command = adCmdText
Text Command = select * from your_table order by DepDate, UnitNo
End Sub

Can you explain where to put your code?

Thanks!
 
Thanks, reneford & DrJavaJoe for the help and here's a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top