using search function and orderby (1 Viewer)

comicwizard

Registered User.
Local time
Yesterday, 19:05
Joined
Mar 24, 2011
Messages
15
Okay,

I am building a database form that uses a sub form. I got the search function to work great, had to copy some code to do so, but now I would like to have the results sorted on a different field.

the Search function uses employee id, then I am trying to add me.orderby to the code to sort by input_Dt desc.

No matter how I fiddle with the orderby I just cannot get the results to sort by input_dt desc. I have removed the me.orderby "[input_Dt] Desc" from the code because it wasn't working.

My thought was I needed to add it to the LSQL = LSQL .... part but I get an error when I do that.
Maybe I am barking up the wrong tree. :banghead:

code is as follows.


private Sub cmdSearch_Click()
Dim LSQL As String
Dim LSearchString As String

If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a correct Employee Number."

Else

LSearchString = txtSearchString


LSQL = "select * from Master_tbl"

LSQL = LSQL & " where Employee_ID LIKE '*" & LSearchString & "*'"

Form_Edit_Form_sub.RecordSource = LSQL


lblTitle.Caption = "Employee_ID: Filtered by '" & LSearchString & "'"

'Clear search string

txtSearchString = ""

MsgBox "Results have been filtered. All Employee_ID containing " & LSearchString & "."

End If

End Sub
 

Ranman256

Well-known member
Local time
Yesterday, 20:05
Joined
Apr 9, 2015
Messages
4,339
to sort, all you do is put the cursor in the field, then click the sort button.
no code needed.
 

comicwizard

Registered User.
Local time
Yesterday, 19:05
Joined
Mar 24, 2011
Messages
15
That is one solution, but I would like to have to auto sort for me.
 

comicwizard

Registered User.
Local time
Yesterday, 19:05
Joined
Mar 24, 2011
Messages
15
I was using orderby = true instead of orderbyon , so my bad, but where in the code would I place this.

I have tried a few spots thinking I just had it in the wrong spot but it still isn't putting the date in desc order.

Thank you for this part.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:05
Joined
May 7, 2009
Messages
19,169
you put it after you set the sorting order:
Me.OrderBy = "your order here"
Me.OrderByOn = True
 

JHB

Have been here a while
Local time
Today, 01:05
Joined
Jun 17, 2012
Messages
7,732
I have tried a few spots thinking I just had it in the wrong spot but it still isn't putting the date in desc order.
I would insert the code lines here:
Code:
Form_Edit_Form_sub.RecordSource = LSQL
Me.OrderBy = "input_Dt DESC"
Me.OrderByOn = True
 

Users who are viewing this thread

Top Bottom