Results 1 to 11 of 11
  1. #1
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98

    Search Criteria for Concatenated Fields?

    I have a field that is concatenated with 4 other fields [LOGDATE], [FIRSTNAME], [LASTNAME], [ITEM]. I am trying to sort out [LOGDATE] with the "to and from" textboxes from my form SearchF. I cannot seem to find a solution other than the DLookup function. I have tried the DLookup function, but can't get it to work and I know I have an error, but can't find the solution as to where. Here is my current code:



    Code:
    Dlookup ("[LOGTIME]", "[SALE]", "[LOGTIME] between [Forms]![SearchF]![fromdate] and [Forms]![SearchF]![todate]")
    Logtime is the field name located in the table "Sale". Thanks in advance!

    EDIT:
    Code:
    Dlookup ("[LOGDATE]", "[SALE]", "[LOGDATE] between [Forms]![SearchF]![fromdate] and [Forms]![SearchF]![todate]")

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What has the concatenated value to do with this?

    I have seen Access resolve references to form controls when they are within quotes so maybe just need # delimiters.

    Dlookup ("[LOGDATE]", "[SALE]", "[LOGDATE] between # [Forms]![SearchF]![fromdate] # and # [Forms]![SearchF]![todate] #")

    or concatenate:

    Dlookup ("[LOGDATE]", "[SALE]", "[LOGDATE] between #" & [Forms]![SearchF]![fromdate] & "# and #" & [Forms]![SearchF]![todate] & "#")

    Where exactly are you using this expression? DLookup will just return the first LOGDATE value it encounters that meets the criteria.
    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
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    Quote Originally Posted by June7 View Post
    What has the concatenated value to do with this?

    I have seen Access resolve references to form controls when they are within quotes so maybe just need # delimiters.

    Dlookup ("[LOGDATE]", "[SALE]", "[LOGDATE] between # [Forms]![SearchF]![fromdate] # and # [Forms]![SearchF]![todate] #")

    or concatenate:

    Dlookup ("[LOGDATE]", "[SALE]", "[LOGDATE] between #" & [Forms]![SearchF]![fromdate] & "# and #" & [Forms]![SearchF]![todate] & "#")

    Where exactly are you using this expression?
    In the criteria field on query design. Thank you for the response by the way.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Using DLookup like that makes no sense if there could be multiple values within the date range. Post the complete query SQL statement. Sample of raw data would also be helpful.
    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
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    It will be tough since the database is proprietary, but is there anything else I can get to help? I have 4 fields combined into one field labeled "Description", but I am wanting to sort "Description" by the [LOGDATE]. DLookup was the only function that any google result showed.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why? Why don't you just include LOGDATE field in the query and apply filter to it?

    Don't really need your proprietary data (and that would be what - names and addresses?). Mock up a table in the post that recreates the table structure but don't use your proprietary data. Use the Advanced Edit window tools. And an SQL statement does not reveal data.
    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
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Databases work very well on the 1 concept 1 field design approach. Why exactly did you concatenate 4 fields?

  8. #8
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    I am designing an export query specifically for importing into quickbooks as invoices. I have to add 4 fields together because you can only import excel into quickbooks with the exact same layout quickbooks uses and in order to add multi-line items into quickbooks, the data has to be setup in a very specific way. The customers sale date, name, and item purchased are all in one description because even though the sale dates are different, they are with the same account so I have to make sure that there is information to let quickbooks know it is a multiline item.

    Code:
    SELECT DateSerial(Year(Date()),Month(Date())+1,0) AS [INVOICE DATE], [LOGDATE] & " " & [FIRSTNAME] & " " & [LASTNAME] & " " & [ITM.NAME] AS Description, SALEITMS.QTY, [Invoice Class].Class, SALE.TOTALFROM [Invoice Class] INNER JOIN ((SALEITMS INNER JOIN ITM ON SALEITMS.ITEM = ITM.OBJID) INNER JOIN ((SALECHGS INNER JOIN ACCT ON SALECHGS.ACCTNUM = ACCT.OBJID) INNER JOIN ((CUST INNER JOIN CUSTCDE ON CUST.OBJID = CUSTCDE.CUST) INNER JOIN SALE ON CUSTCDE.OBJID = SALE.CUSTCDE) ON (SALECHGS.STE = SALE.STE) AND (SALECHGS.SALEID = SALE.OBJID)) ON (SALEITMS.SALEID = SALE.OBJID) AND (SALEITMS.SITE = SALE.SITE)) ON ([Invoice Class].Site = SALECHGS.SITE) AND ([Invoice Class].Site = SALE.SITE)
    GROUP BY ACCT.NAME, SALE.CREATED, DateSerial(Year(Date()),Month(Date())+1,0), [LOGDATE] & " " & [FIRSTNAME] & " " & [LASTNAME] & " " & [ITM.NAME], SALEITMS.QTY, [Invoice Class].Class, SALE.TTL, ITM.NAME
    HAVING (((ACCT.NAME)=[Forms]![SearchF]![actname]) AND ((SALE.CREATED) Between [Forms]![SearchF]![fromdate] And [Forms]![SearchF]![todate]));
    I have hopefully masked well enough the information that I feel is sensitive, but it is the best that I will be able to do in terms of providing the SQL.

  9. #9
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    Found a work around. Instead of trying to filter Logdate inside of the concatenation, I just created a new query that filtered the logdate and then put that new query into the concatenation in place of logdate. I apologize for the minute amount of background info, but I appreciate all the help. Ill be marking this as solved for now.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    BTW, Name is a reserved word and should not use reserved words as names for anything. Also, advise to avoid spaces in naming convention, even in alias names, so INVOICE DATE would be better as InvDate or INV_DATE.
    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.

  11. #11
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    Quote Originally Posted by June7 View Post
    BTW, Name is a reserved word and should not use reserved words as names for anything. Also, advise to avoid spaces in naming convention, even in alias names, so INVOICE DATE would be better as InvDate or INV_DATE.
    Notated 👍 Thank you.

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

Similar Threads

  1. Cannot get DLookUp to work with concatenated criteria
    By sportyaccordy in forum Queries
    Replies: 7
    Last Post: 07-21-2016, 09:12 AM
  2. Replies: 2
    Last Post: 07-02-2015, 02:24 PM
  3. Query criteria fields flooded after search
    By a12ctic in forum Queries
    Replies: 1
    Last Post: 06-27-2011, 06:25 PM
  4. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 PM
  5. Sum values in concatenated fields
    By jdrubins in forum Reports
    Replies: 4
    Last Post: 09-01-2009, 07:20 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