Results 1 to 10 of 10
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    How to LookUp from table within Fact(Summary)Table?

    Hi,



    this is the continuity from here:

    https://www.accessforums.net/showthread.php?t=67142

    there I am trying to create the best efficient relational database model.

    Here i would like to find out the solution for lookup within the fact table.

    I have summary table with IDs(not Uniques!) and a lot of attributes like: name and surname, sending date, employeeID, DocumentID,Client_Nr_FK etc.

    and additionally i have second table filled manually by administrator - this is a lookup table or dictionary table you can call it like that.

    ID (the same as in Fact Table), director, area and e-mail. ID is a field which should match with ID field in Summary Table.

    And know i need a macro or query or something like that which will be checking all rows in my Fact table which are macthing with my lookup table values.

    Example:

    Fact Table:
    UniqueID , ID , Name_And_Surname , Area , Sending Date, EmployeeID, DocumentID, Client_Nr_FK
    1, 1001, Pawel X , Wroclaw, 2017-07-25 , 5 , 2 , 1
    2, 1001, Pawel X , Wroclaw, EMPTY HERE, 5 , 2 , 1

    LookUp table:
    UniqueID, Director, Area, E-mail
    1001, Michal Z, Poznań, a@interia.pl
    1001, Michal Z, Warsaw , b@interia.pl
    1001, Michal Y, Wroclaw, c@interia.pl

    Area is a text value unfortunately, i could not force business to change it.
    But it doesnt matter for now, i have to have clear idea in my mind how to solve this difficult technical problem.

    So my macro should:
    1. Check all rows if Sendind Date is empty (so only UniqueID = 2 in example above because Sending date is empty here)
    2. If yes should be sending email (reminder) for specific criteria:
    - find in lookup table exact machting ID
    - check the area for found ID -if it is the same as in Fact Table --> send for given email

    So here e-mail should be send for E-mail c@interia.pl because Area and ID is the same as in Fact table...

    Every hint from you guys here will be most welcome,
    Best Wishes,
    Jacek Antek

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    First step, create a query and add both tables. Join them on those two fields. Add the fields you want returned, including the date field. Put this in the criteria of the date field:

    Is Null

    and see if that returns what you want. If so, open a recordset on it and send emails within a loop of that recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Wow pbaldy your tip makes my day.

    Sorry for late answer - i will write here if i do appropriate model and query.

    Best Wishes,
    Jacek Antek

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Okey,

    first problem here.

    I had join the tables as you wrote and problem is that my ID field is not only one with i should treat as criteria (or filter if you want to say that).

    So i have one additionally field here - Area which is criterion.

    So after combining these tables i have result table like below:

    UniqueID , ID , Name_And_Surname , Area , Sending Date, EmployeeID, DocumentID, Client_Nr_FK
    1, 1001, Pawel X , Wroclaw, 2017-07-25 , 5 , 2 , 1
    2, 1001, Paweł X, Warszawa, 2017-07-25 , 5 , 2 , 2

    With your solution i got rid of unnecessary IDs here.
    Problem is that ID is connected with 2 different Areas.


    I have to send email only for record with UniqueID = 1 because in my lookup table there is criteria (Client_Nr_FK) which corresponds to Client Name.
    So in lookup table i have
    Client_Nr_FK = 1 and Area = Wroclaw so e-mail shoud be sent exactly to e-mail attached to it.

    other words:
    From fact table we know that Pawel X has Area for specific client : Wroclaw - so i have to somehow join our tables in order to get only record with Wroclaw criteria.
    With inner join i can get only IDs which i need but i have to somehow do it additionally for Area criterion field.

    In qlikview i would simple create the new unique key containing 2 fields: ID & Area and your solution will work here.
    In Access i do not know it is good idea.

    I have found the solution here:

    https://stackoverflow.com/questions/...join-in-access

    but i have an error joining when I am trying add new relationship between Area field in fact table and in lookup table.

    How can i solve this additionally?
    Create composite key within my query? How?

    Best wishes,
    Jacek Antek







  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You haven't shown your attempt or said what the error was, so I'm shooting in the dark here. Are the field in the join of compatible data types?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you pbaldy for your help.

    Ok i compacted database and this is working like a charm now.

    My steps in order to do it:
    1. I created Query "QryRemindersFirst" with all required fields:

    Click image for larger version. 

Name:	Bez tytu?u.png 
Views:	17 
Size:	44.0 KB 
ID:	29690

    Here I am taking all data from my Fact Table which i need.

    2. I created Query "QryReminder" where I am taking all fields from lookup table and adding the name of company with relationship:

    Click image for larger version. 

Name:	Bez tytu?u2.png 
Views:	18 
Size:	108.2 KB 
ID:	29691

    3. The last step I created with these 2 queries the last queries which is combining only these records which i want to show (with WHERE criteria):

    Click image for larger version. 

Name:	Bez tytu?u3.png 
Views:	18 
Size:	32.4 KB 
ID:	29692

    4. This relationship give us result table like here (i had to change data in order to data protection):

    Click image for larger version. 

Name:	solution.jpg 
Views:	18 
Size:	97.1 KB 
ID:	29693

    This is awesome, thank you for you tip!

    And now my VBA code can loop through all rows and send e-mail to each of user.

    First new problem:
    Now it is the hard part: i have to write code which will be looping and sending only one e-mail --> for example Adach Anna.
    So Adach Anna has the same company, the same SAP_nr, the same Email and EmailDW. Only difference is document name.

    How to show it, maybe delete repating records and leave only Documents?

    Second new problem:
    How to insert for each document name the reminder_date? Also use code and SQL commend insert into ?

    Thank you for your help !
    Best Wishes,
    Jacek Antek

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Have to run out for a while, but check out these two:

    http://allenbrowne.com/func-concat.html

    http://www.granite.ab.ca/access/email/recordsetloop.htm

    The second has some extra stuff in it, but hopefully gets you started.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hello pbaldy,

    thank you very much !

    Your links are very useful,
    I have already handled it, i will describe my full database with example in another topic:

    https://www.accessforums.net/showthr...758#post365758

    Warm regards,
    Jacek Antek

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 06-02-2017, 03:49 PM
  2. Query to calculate summary from table.
    By SybRiN in forum Queries
    Replies: 5
    Last Post: 04-21-2017, 08:14 AM
  3. CrossTab to Summary Table
    By Dennis Willis in forum Queries
    Replies: 3
    Last Post: 06-09-2014, 01:06 PM
  4. Replies: 3
    Last Post: 06-28-2013, 01:59 PM
  5. Replies: 8
    Last Post: 03-22-2012, 08:48 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