Full Version: Vba Event Programming Before A Sort/filter
UtterAccess Forums > Microsoft® Access > Access Forms
steveny
I have a subform in datasheet view. If a user wants to sort or filter the records on the subform, which they can do by clicking the header of a field column, is there a way for me to program an event before the sort or filtering occurs?
KRoth472
steveny,
You might set the Shortcut Menu property = no. Then add a checkbox to the form with the following code:
If Me.Check1.Value = True Then
'do someaction here before sort
'then do the sort (below)
With Me!ViewEditPOInformation_SubForm.Form
.Filter = "Fieldname = 'Criteria'"
.FilterOn = True
End With
Else
Endif
Also. Have you tried to program your action in the BeforeUpdate Event of the form/subform?
HTH
steveny
Hi,
The users are used to selecting the field header they want to sort by. If I did your first suggestion how do we know which column was selected to know what to sort or filter by.
Also, I tried using the BeforeUpdate event but it does not get triggered when the user selects a column to sort.
Steve
KRoth472
Steve,
If they are filtering for a user defined criteria like doing a Left-Click = > Text Filter = >Equals and then typing their search criteria it might be best to do a textbox with a command button and then attaching the code:
'do someaction here before sort
'then do the sort (below)
With Me!ViewEditPOInformation_SubForm.Form
.Filter = "Fieldname = " & CreatedTextBox
.FilterOn = True
End With
Also try adding the code to the current event. In the order of events on forms it goes Current => Before Update = > After Update = > Current. Here the link to the article on the MS website http://office.microsoft.com/en-us/access-h...238988.aspx#BM3
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.