Results 1 to 7 of 7
  1. #1
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528

    query get an error

    Hello Guys


    I have two tables I've worked a query based on them
    When you run the query get an error
    ــــــــــــــــــــــــــــــــــــــــــــــــــ ــــــــــــــــــــــــ
    SELECT DISTINCT tblWeight.Patid, tblWeight.FirstName, tblWeight.LastName, Table1.Weight, Table1.Date, DMax("Date","tblWeight" And "TABLE1","Patid=" & [Patid]) AS LastVisitDate, DLookUp("Weight","tblWeight" And "TABLE1","Patid=" & [Patid] & " and Date = #" & [LastVisitDate] & "#") AS LastVisitWeight, DMax("Date","tblWeight" And "TABLE1","Patid=" & [Patid] & " and Date < #" & [LastVisitDate] & "#") AS PrevVisitDate, IIf(IsNull([PrevVisitDate]),Null,DLookUp("Weight","tblWeight" And "TABLE1","Patid=" & [Patid] & " and Date = #" & [PrevVisitDate] & "#")) AS PrevVisitWeight, ([LastVisitWeight]-[PrevVisitWeight])/[PrevVisitWeight] AS WeightDifference
    FROM tblWeight INNER JOIN Table1 ON tblWeight.PatID = Table1.NameID
    ORDER BY tblWeight.Patid;

    Click image for larger version. 

Name:	222.PNG 
Views:	11 
Size:	14.9 KB 
ID:	17825
    Click image for larger version. 

Name:	333.PNG 
Views:	11 
Size:	15.9 KB 
ID:	17826

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    We really can't see the last 2 fields which I believe is where the error is coming from. Check the string for errors.

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    OK burrina
    Thank you for your interest burrina
    This is DB
    Attached Files Attached Files

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    1. dont use DLOOKUP in queries. The query IS the lookup. You would add the lookup table as part of the query.

    2. I see nothing wrong in the SQL so the -1 is coming from a either lookup or a return param.

  5. #5
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Thank you very much
    But it has not succeeded

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Date is a reserved word. Should avoid reserved words as field names.

    Domain aggregate cannot reference two tables. This is improper syntax.
    PrevVisitDate: DMax("Date","tblWeight" And "TABLE1","Patid=" & [Patid] & " and Date < #" & [LastVisitDate] & "#")

    Don't need tblWeight in the expression. Table1 has the data. Use NameID instead of PatID.

    PrevVisitDate: DMax("Date", "TABLE1", "NameID=" & [NameID] & " and [Date] < #" & [LastVisitDate] & "#")
    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
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Thank you very much.
    ahoowoowoowo how beautiful and crazy ِAccess

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

Similar Threads

  1. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  2. Query Error 3075 Syntax Error
    By jbailey4545 in forum Queries
    Replies: 8
    Last Post: 03-11-2014, 01:34 PM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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