Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

vba - Disable Filtered/Unfiltered and Toggle Filter Buttons in MS Access

In MS Access, I have two forms (running off one table) that has a pre-defined on-load filter for each. My end-user likes to click the Toggle Filter or Filtered button as a means to clear any filters they've used within the form's table. This effectively brings records from the other form into the form they're working on.

I want to be able to disable these two buttons whilst still giving them the ability to use the sort/filter within the form's table's drop-down arrows.

How would this be achieved?

I have already tried using:

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
  Cancel = ApplyType = 0
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would bind those forms not to the table directly, but each to a separate query, which only provides the desired records.

  • MyQuery1 for form 1:

    Select * From MyTable Where MyField = '1'

  • MyQuery2 for form 2:

    Select * From MyTable Where MyField = '2'

In each forms Record Source property do not reference the table MyTable but the desired query MyQuery1 or MyQuery2.

Alternatively you can directly enter the shown sql statements into the forms Record Source properties.

So your users can filter as they want but never get 'unallowed' data, because the forms record source doesn't contain that data at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...