Results 1 to 10 of 10
  1. #1
    prs312 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    11

    DLookup between text fields to use in calculated expression

    I’m having difficulty using DLookup in a query to calculate the “Morphine Equivalent Dosage (MED)” for medications taken. I have two tables and a query:
    • tblTreatment – lists a medication taken, the dosage, and number of pills (this table is uploaded from excel)
    • qryTreatment – based off of tblTreatment
    • tblMEDLookup – lists medications and there morphine equivalent dosage (MED)

    I'm trying to add a column to qryTreatment (called MED_Med1) that looks up the MED for a a medication taken (from tblMEDLookup) and multiplies it by the Dosage taken and Number of pills (from tblTreatment). The following picture illustrates this.

    Click image for larger version. 

Name:	DlookupIssuePic.png 
Views:	10 
Size:	163.1 KB 
ID:	19161
    The expression I've tried to implement in qryTreatment to get MED_Med1 is the following:
    MED_Med1: DLookUp("MED","tblMEDLookup","Analgesic= '" & Nz("[RescueMed1]",0) & " ' ")*([tblTreatment]![RescueMedDose1])*([tblTreatment]![RescueMedPill1])
    So far this only returns blank values as shown below:
    Click image for larger version. 

Name:	ExpressionUsed.png 
Views:	10 
Size:	258.8 KB 
ID:	19162
    Any help on this issue would be very much appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    What field type is RescueMed1? If it is a number type and its actual value is the ID from tblMedLookup, that's why you get no results. The DLookup is referencing wrong field in the criteria.

    Are you setting Lookup fields in table? Review: http://access.mvps.org/access/lookupfields.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    prs312 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    11
    the Data Type of [RescueMed1] is Short Text. and there aren't any lookup fields in tblTreatment, that table is imported as is from excel.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Then I am at a loss as to why the DLookup fails. But why are you using DLookup instead of just joining tables in query?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    prs312 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    11
    The reason I can't join the two tables is that the tblTreatment is uploaded and may show records in which a patient takes a new medication that isn't already listed in tblMEDLookup. Therefore each medication must be typed in the exactly the same in tblMEDLookup and the MED for that med specified. Attached is a stripped down version of the database for clarification.

    Clinical Database-stripped.zip

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Regardless if the tables are joined or you use DLookup, the Med values must be in tblMedLookup. Don't use INNER JOIN in the query, use RIGHT JOIN.

    Not finding DLookup on tblMedLookup in qryTreatment.

    Multiple similar name fields (RescueMed1, RescueMed2, etc) indicates a non-normalized data structure. This can cause lots of issues with data search and analysis. Because of this structure, would have to include tblMedLookup in the query 10 times, one for each RescueMedx field or have 10 DLookup expressions. Domain aggregates can slow down query performance.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    prs312 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    11
    Thanks, the RIGHT JOIN allowed me to get the MED values in the qryTreatment. you are right about the non-normalized data structure, but because this table is uploaded as is I'm forced to leave it that way and, like you said, include tblMedLookup in the query 10 times.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Are you linking to the data or importing?

    The data could be rearranged into a normalized structure. One way is with UNION query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    prs312 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    11
    I'm importing so don't think I can change the structure.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    There are ways to import data into whatever structure you want. You just have to decide if it's worth the effort.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-27-2014, 06:42 AM
  2. Replies: 12
    Last Post: 10-01-2013, 12:59 PM
  3. Replies: 4
    Last Post: 09-02-2013, 03:00 PM
  4. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  5. Replies: 1
    Last Post: 04-25-2011, 12:36 PM

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