True Rich, dcx ... both ways will do the job.
Well, I found a code where I can sort the data in form ..
It's as follows:
Option Compare Database
Option Explicit
Const cstrOldSQL = "SELECT .....
I created a CmdButton named CmdSort
Private Sub CmdSort_Click()
'Set the constant for the default form RecordSource
Const cstrOldSQL = "SELECT ...
Dim strNewSQL As String ' variable to hold the new SQL string for the RecordSource
Select Case Me!optSortBy
Case Is = 1
' Sort by Id No returns 1
strNewSQL = cstrOldSQL & " ORDER BY [tIdNo];"
Case Is = 2
' Sort by Product Id returns 2
strNewSQL = cstrOldSQL & " ORDER BY [tProductId];"
Case Is = 3
' Sort by Date returns 3
strNewSQL = cstrOldSQL & " ORDER BY [tDate];"
Case Else
' Handle the instance where an unexpected value is returned
strNewSQL = cstrOldSQL & ";"
End Select
' Assign put the new SQL value into the recordsource
Me.RecordSource = strNewSQL
Me.Requery
End Sub
This code exactly suits what I need. But now my problem is different... I created a report and I want to set the criteria to print recorts in the same order as in form...
Private Sub CmdPreview_Click()
On Error GoTo Err_CmdPreview_Click
Dim stDocName As String
Dim stLinkCriteria As String
'stLinkCriteria = "[orderby]=" & Me!optSortBy
stDocName = "rptPurchaseFromTo-Sort"
DoCmd.OpenReport stDocName, acPreview
I don't know how to use select case in setcriteria...
Hope anyone can help me.
Thank you all.