I am changing the FILTER, ORDERBY, and ORDERBYON attributes of an Access 2007 form. I have code tied to buttons on the form that resort and/or refilter the records of a datasource based on user selections.
When the form is closed, I am trying to wipe out any parameters that have been set in these attributes in order to try and put the form back in its original state, when these attributes were empty. See code I'm using below:
================================================== =======
Private Sub Form_Close()
On Error GoTo Err_Form_Close
'prevent unintentional form updates
Me.Filter = vbNullString
Me.OrderBy = vbNullString
Me.OrderByOn = False
DoCmd.Close acForm, Me.FormName, acSaveYes
Exit_Err_Form_Close:
Exit Sub
Err_Form_Close:
If (Err = 2501) Then
Resume Next
End If
MsgBox Err.Description
Resume Exit_Err_Form_Close
End Sub
================================================== =======
I have played with the "docmd". In the current code, I try to wipe out the values and save the form. I have also tried using ACSAVENO, with the thinking being that if I answered no, Access would not keep any of my changes. It doesn't seem to matter, because when I close the form and reopen in Design View, the last set of values from the form are in the ORDERBY and FILTER attributes.
I just added the err logic, in the hopes of making this work. But I thought I would see if someone could help while I try to figure this out. Any help would be GREATLY appreciated.