Rabu, 24 Agustus 2011

[MS_AccessPros] When load form store filter and click reset button to reset filter

 

Good morning! I am using Access 2007. I have a form Listings that is currently opened in two different ways. One button on another form opens the Listings form with a where condition. The code behind that button is:

DoCmd.OpenForm "Listings_AllChange", , , "CurrentListing = -1"
Forms!Listings_AllChange.FormTitle.Caption = "Current Listings"
Forms!Listings_AllChange.Caption = "CurrentListings"

The toggle filter button on the ribbon is highlighted and pressing it makes the source go from all records, to current listings, and back.

I want to store the filter that is used when this form is opened so that no matter what filter or non filter is applied, it can be reapplied. The On Load property where I'm trying to get the filter has this code which I'm pretty sure is not correct:

Dim strFilterListings_AllChange As String
DoCmd.GoToRecord , , acNewRec
strFilterListings_AllChange = strFilterListings_AllChange & " & Me.Filter & "

The Listings form has a header with search boxes and a button to reset the search boxes to "". I would like that reset button to apply the filter or nonfilter that was applied upon opening. Or should I say the where condition? Here's the code I have:

'Reset filter and source of records
Me.Filter = ""
cboSearch = ""
If Me.FilterOn = True Then Me.FilterOn = False
Me.Filter = strFilterListings_AllChange
Me.FilterOn = True

As you can see below when I search for a "non current" listing name it looks at the recordsource without the filter. How can I change that code to add the filter? .

The code behind the search box is:
Private Sub cboSearch_AfterUpdate()
'~~~~~~~~~~~~~~~~~~~~~~Error Handler came from Crystal
'set up Error Handler
On Error GoTo Proc_Err
'~~~~~~~~~~~~~~~~~~~~~~

Dim strSql As String

If IsNull(Me.cboSearch) Then
'If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "qListings_All"
Else
strSql = "SELECT DISTINCTROW qListings_All.* FROM qListings_All " & _
"INNER JOIN ListingContacts ON " & _
"qListings_All.ListID = ListingContacts.ListID " & _
"WHERE ListingContacts.ContactID = " & Me.cboSearch & ";"

Me.RecordSource = strSql
End If

thank you!
Connie

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar