Results 1 to 8 of 8
  1. #1
    Trial4life is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2022
    Posts
    33

    Filter a report by a column which is auto-calculated from a different table

    Hello,
    I'm trying to filter a Report by a column of a Form which is auto calculated (using data of a different table) using a DLookUp expression (which reads the data from a different table), but the filter options are grayed out.

    Click image for larger version. 

Name:	2022-03-11 12_05_24-Window.png 
Views:	38 
Size:	4.2 KB 
ID:	47420



    If I try to filter the report using another column which is not autocalculated (but refers to a column of the direct table which the Form is linked to), the filter menu turns on again.

    Click image for larger version. 

Name:	2022-03-11 12_06_21-Window.png 
Views:	37 
Size:	4.2 KB 
ID:	47421

    If I want to filter the Report in this way, I have no options but to export the Report to an Excel sheet, and apply a filter to the desired column using the string criteria I need.

    I was wondering if there is a way to "force" the filter directly in Access, using just the "RAW" data that comes out from the DLookUp expression and that are displayed on the Report view, so that I can directly export the Report to a PDF, saving a lot of time. The problem seems to be related to the fact that I'm using the DLookUp expression to calculate the column I want to filter, so the Form can't see the data because it is indeed calculated from a different table.

    Thanks in advance.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    A calculated control cannot be bound. If it can't be bound, it's not part of the underlying data (at least not in any fields), thus you cannot filter on it. If the parts of the calculation are fields in the underlying data, you could filter using the component parts as criteria. If they're not (e.g. you have an underlying query that provides the report data but only the calculated query field is passed to the report) then you'd have to split up the parts that are actually data in fields and apply a report filter using those. Far better to include the fields in the query even if you don't display them individually on the report, and easy enough to hide those fields.

    Many will use a some sort of form with controls to provide criteria, and a combo with a list of reports. When you click the button, the report opens, filtered as required. Perhaps that is something that will make your job easier.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Move the dLookup from the form itself (in the control's control source) to the form's record source.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Trial4life is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2022
    Posts
    33
    I've tried to schematize in this image (simplifiyng as much as possible) what I'm trying to achieve:

    Click image for larger version. 

Name:	2022-03-11 22_29_29-Window.png 
Views:	21 
Size:	6.5 KB 
ID:	47423

    Quote Originally Posted by Gicu View Post
    Move the dLookup from the form itself (in the control's control source) to the form's record source.

    Cheers,
    I had already tried to move the DLookUp formula from the form to the record source (Table B), in the following way:

    Click image for larger version. 

Name:	2022-03-11 22_33_04-Window.png 
Views:	21 
Size:	9.0 KB 
ID:	47426

    but when I try to save the Table B, I get this error window:

    («The expression cannot be used in a calculated column»)

    Click image for larger version. 

Name:	2022-03-11 22_33_42-Microsoft Access.png 
Views:	22 
Size:	3.4 KB 
ID:	47425

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    That was not what I suggested. If your form is bound to table "TABLE B" and you are looking up a matching value in table "TABLE A" open up your form in design view and in the record source property (in the Properties window) replace TABLE B with :
    Code:
     SELECT * FROM [TABLE B], Dlookup("NAME","[TABLE A]","ID='" & [ID] & "'") As YourCalculatedNameField;
    Once you do that go to the textbox on the form and in its control source replace the calculation with the calculated field (YourCalculatedNameField) from the query.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Trial4life is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2022
    Posts
    33
    I've tried to do what you suggested, but as soon as I try to change the record source with the code you wrote, I get the error message: «Syntax error in FROM clause».
    Also, note that the form is linked to Table B, but I'm displaying also other columns of the Table B itself, not only the column "Name" from Table A.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Show please what you tried (the real names of the tables and fields), you select all tables from Table B (hence the "SELECT *") and you add your calculated dLookup field.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Trial4life is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2022
    Posts
    33
    I managed to achieve what I was trying to do by just avoiding the DLookUp, and creating a new query from scratch. I created then a report directly from the new query, and now the filter works properly for all of the fileds in the report linked to the query.

    Thanks for the help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 03-16-2018, 08:26 AM
  2. Calculated Column in a Table
    By asmith533 in forum Programming
    Replies: 1
    Last Post: 02-10-2015, 07:53 AM
  3. Replies: 2
    Last Post: 10-29-2013, 04:38 PM
  4. Calculated column in a report
    By beanhead0321 in forum Reports
    Replies: 2
    Last Post: 08-16-2011, 08:48 PM
  5. Replies: 8
    Last Post: 08-09-2011, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums