Results 1 to 6 of 6
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    DLookup with 2 conditionals

    Hi everyone,




    I want to join two conditions for my DLookup but after trying I couldn't

    How Can I joint this two conditions? ... I tried with "And" but I cound't make it work

    '************************************************* ********************************
    Me.EquipoM = DLookup("[Name]", "[Work_Team]", "[LineProduction]= '" & Me.Line_Production & "'")
    Me.EquipoM = DLookup("[Name]", "[Work_Team]", "[Departament]= 'Production'"

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Why not post what you tried and we can probably advise where you went wrong? I'm thinking you might learn more from that exercise.
    If you prefer, I or someone else can probably just do it for you.

    EDIT - make sure your object names are consistent e.g. "Departament" looks misspelled here.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Yes you're right the idea is to learn and I made that but it did'nt work

    This is what I did...

    Me.EquipoM = DLookup("[Name]", "[Work_Team]", "[LineProduction]= '" & Me.Line_Production & "'" And "[Department]= 'Production'")


    I edited... 'Departament... good point

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The ampersand is the concatenating operator, yes? And each parameter of the function needs to be enclosed in quotes. Your "And" is part of the last parameter (the criteria portion) but it lies outside of your quotes. It's kind of 'orphaned'. I think this is more like what you need (I didn't know what to do with department now so I left it as is):

    Me.EquipoM = DLookup("[Name]", "[Work_Team]", "[LineProduction]= '" & Me.Line_Production & "' AND [Departament]= 'Production'")

    I have to assume that [Departament] is a field in the table, not a control on the form. Hopefully that expression is correct. One way to check your work and trouble shoot is to replace what comes between the quotes with literals. If I do that, the expression should evaluate to (the value I chose isn't important to the explanation):

    Me.EquipoM = DLookup("[Name]", "[Work_Team]", "[LineProduction]= 'Production1' AND [Departament]= 'Production'")

    2 other comments
    - you don't allow for the possibility that the lookup could return Null (or at least it's not obvious)
    - I'm assuming the criteria values are text. If not, they may need some other type of delimiting, just not a single quote. Numbers don't get delimited.
    Last edited by Micron; 04-20-2020 at 01:11 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Oh sorry Department is also a field that belongs to the same table "[Work_Team], so both criteria belongs to the same table.

    Departments according to the data contained into the table could be.... Quality, Production, Engineering, Human_Resources, etc

    It makes a change into my criteria?




  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Not sure what you are saying/asking because I get that both fields are in the same table. The change it has on your criteria expression is relevant to how it needs to be concatenated.

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

Similar Threads

  1. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  2. If and Dlookup
    By Zinger in forum Programming
    Replies: 6
    Last Post: 10-17-2015, 04:47 PM
  3. Need help with a DLookup using Or
    By jax1000rr in forum Queries
    Replies: 1
    Last Post: 05-06-2013, 11:18 AM
  4. DLookup help
    By denners05 in forum Access
    Replies: 1
    Last Post: 06-11-2011, 12:55 PM
  5. DLookup
    By smidgey in forum Forms
    Replies: 13
    Last Post: 01-19-2011, 09:27 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