me.filter and sort?

JudyHNM

New Member
Joined
Dec 21, 2015
Messages
18
I have the following code which filters a form for me, and it works fine, but I would like to add a sort order (based on two fields) to it. How can I do that?
Code:
Private Sub cmdFilter_Click()
'Purpose:   Create dynamic screen report using form frmVersionList
'Date:      04/30/17




Dim strWhere    As String       'Criteria string
Dim lngLen      As Long         'Length of criteria string to append to


'********************************************************************
'Look at search box(es) and build criteria string from non-blank ones
'********************************************************************
    
    If Not IsNull(Me.txtFilterDesignName) Then
        strWhere = strWhere & "([tblP_DesignName] LIKE ""*" & Me.txtFilterDesignName & "*"")"
    End If


'********************************************************************
'Apply string as the form's filter
'********************************************************************
    Me.Filter = strWhere
    Me.FilterOn = True
    


End Sub

Thanks, Judy
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The sort order is part of the WHERE. Make a query and view its SQL.

I understand what you are saying by I can't figure out how to add the order by part to the where statement. Can you provide any help with that?

thanks, Judy
 
Upvote 0
Add on the end: ORDER BY [field]

(just like a query does it)

Sorry, I should have been more specific. I did realize that I needed "ORDER BY [field]", but I can't get the syntax/format/punctuation right.

I have tried both of the ones shown below plus some other variations, and I continually get Error 3075 "missing operator.
Code:
strWhere = strWhere & "([tblP_DesignName] LIKE ""*" & Me.txtFilterDesignName & "*"") & Order by [tblP_Designname]"       
strWhere = strWhere & "([tblP_DesignName] LIKE ""*" & Me.txtFilterDesignName & "*"") & Order by [tblP_Designname]"""

Can you either provide or point me to an example that will show the correct format?

Thanks, Judy
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top