Results 1 to 8 of 8
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Update with a DLookup

    I'll admit this right off, dlookups bother me. I use them all the time, but they bother me. Sometimes they work fine. This is not one of them. Here goes.

    Here's the function as is



    Code:
    DLookUp("[User_ID]","tblUser"," Left([tblOpenItemComments]![Vendor_Name],1) between [From] and [To]")
    I have also tried this way with the same results.
    Code:
    DLookUp("[User_ID]","tblUser"," Left([Vendor_Name],1) between [From] and [To]")
    The expression you entered as a query parameter caused the following error. Microsoft Access cannot name ([tblOpenItemComments]![Vendor_Name] you entered in the expression.
    I have it in a SELECT query just for testing, but I will be using to update a field in tblOpenItemComments. Here's the SQL.

    Code:
    SELECT User_ID, 
    Vendor_Name, 
    Left([Vendor_Name],1) AS Initial, 
    DLookUp("[User_ID]","tblUser"," Left([tblOpenItemComments]![Vendor_Name],1) between [From] and [To]") AS UserID
    
    FROM tblOpenItemComments
    
    WHERE tblOpenItemComments.User_ID Is Null AND tblOpenItemComments.Vendor_Name) Is Not Null
    I suspect this is the wrong way of going about this. I even suspect what the problem is, but for the sake of time tell me if this is a dead end or not would be helpful.

  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,770
    Maybe you should explain what you are trying to do, because I don't understand.

    The DLookup will return the first User_ID encountered that matches the criteria. Since you already have User_ID in the data, why do you have to look for it?
    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
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I don't see how the DLookup will work at all. You are doing a lookup on the table tblUser, but your criteria are referencing data from a different table. In order for DLookup to work as expected, your criteria have to reference field(s) in tblUser that will identify which record to retrieve data from.

    What is the data you are trying to get from tblUser, and how are you identifying it, i.e. the table row?

  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,770
    Actually, the criteria is referencing field of the query source table but the reference is within quote marks and should probably instead be concatenated. At first glance I also thought another table was referenced.

    However, still don't understand why the DLookup is used at all.
    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
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Actually the query I posted is misleading. The User_ID field in this table is empty. I will be updating it based on the result from the DLookup. Once I get it to work I'll use it in an update query which will look something like this.

    Code:
    UPDATE tblOpenItemComments SET tblOpenItemComments.User_ID = DLookUp("[User_ID]","tblUser"," Left([Vendor_Name],1) between [From] and [To]") 
    WHERE tblOpenItemComments.User_ID Is Null AND tblOpenItemComments.Vendor_Name Is Not Null;

    When I run it this way I just get a generic error "Unknown".

    It doesn't seem to matter whether I put the table name in the DLookup or not. Does that help?

  6. #6
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Put simply, I can't see to pass this value, Left([tblOpenItemComments]![Vendor_Name],1) to the function.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Concatenate.

    Vendor_Name is a field in tblOpenItemComments?

    From and To are fields in tblUser?

    UPDATE tblOpenItemComments SET tblOpenItemComments.User_ID = DLookUp("[User_ID]", "tblUser", "'" & Left([Vendor_Name],1) & "' Between [From] And [To]")
    WHERE tblOpenItemComments.User_ID Is Null AND tblOpenItemComments.Vendor_Name Is Not Null;

    Why would you do the lookup with a single letter as the parameter?
    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.

  8. #8
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    1. Concanonete, that work.

    1. Yes

    2. Yes

    3. This worked.

    4. Because users are assign work base on the first letter of the vendor name.

    User1 = A - D
    User2 = E - J
    etc.

    Thanks for your patience.

    Paul

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  2. Update Using Dlookup
    By Cap Heresy in forum Queries
    Replies: 6
    Last Post: 03-14-2013, 03:59 PM
  3. Replies: 1
    Last Post: 02-26-2013, 01:45 PM
  4. Update Function Like DLookup
    By EddieN1 in forum Access
    Replies: 1
    Last Post: 01-04-2013, 12:31 PM
  5. Replies: 1
    Last Post: 01-22-2011, 12:23 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