How to enable filtering on a field defined by DLOOKUP()?

不羁的心 提交于 2020-01-05 05:35:11

问题


I have a form TForm based on table T, set up as a datasheet. My goal is to add a filterable column to the datasheet where the column's value is calculated from a query using another column's value.

I tried to do this by adding a text box currentBox to T. The control source for currentBox is:

=DLookUp("name","currentStatus","itemID=" & [ID])

where [ID] is a field in T and currentStatus is an aggregate query on a table that T is related to.

I can filter on all the fields in TForm that are in T. But I can't filter on currentBox, even though it also appears as a column in the form; clicking on the column header doesn't do anything.

I'm guessing the problem is that currentBox is not bound to a field in T; is there a way to work around this?


回答1:


Here's a VBA solution:

  1. Add a combo box (aka drop-down) object to your form header. This drop-down's source will be an independent query that displays all the values your Dlookup() currently pulls (names?) and stores the itemID. Let's call it ObjPickName in this example.

  2. Add an AfterUpdate event to ObjPickName that will filter your form for you (your form will still be based on T). The code will be something like:

    Private Sub Combo_ObjPickName_AfterUpdate()
    Me.Form.Filter="[itemID]='" & Me.Combo_ObjPickName.Value & "'"
    Me.Form.Filteron=True
    End Sub




回答2:


The way that I ended up solving this was to add a field to T, and have that field updated during the AfterUpdate() event with the value from the DLookup() call. Because the field is now no longer query-based, it can be used to filter the form.



来源:https://stackoverflow.com/questions/17576613/how-to-enable-filtering-on-a-field-defined-by-dlookup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!