Results 1 to 6 of 6
  1. #1
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84

    Dlookup over 2tables AND referring to a combobox


    Click image for larger version. 

Name:	Dlookup.png 
Views:	15 
Size:	29.3 KB 
ID:	33176
    Dear,

    As shown in the screenshot above, I have got 2 tables, i.e. "Jaartabel" and [Extra Opvang] which are related.

    Now, what I want to achieve is, depending on the year selected by a combobox (cboYear in form "Mainform"), the correct record is selected from the [Extra Opvang] table. The year however is in table "Jaartabel"

    Thus, I'm looking for something like : DLookUp("[Maandprijs ExtraOpvang]";"Extra Opvang";"[ExtraOpvangType]='X VM'" AND WHERE [Jaartabel].[Jaartal]= Value of cboYear

    First part of the Dlookup function is working , but I'm looking for the code of the 'bold part'

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    This should be correct:
    Code:
    DLookUp("[Maandprijs ExtraOpvang]","Extra Opvang","[ExtraOpvangType]='X VM' And [Jaartabel].[Jaartal]=" & cboYear)
    NOTE: The DLookup separators are normally commas as shown
    You used semicolons - if that is correct for your regional settings, swop them back
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84
    Hi ridders52,

    The Expression builder returns no error, however, the result is #Name?

    Click image for larger version. 

Name:	Dlookup.png 
Views:	12 
Size:	47.7 KB 
ID:	33178

  4. #4
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84
    The first part is working: DLookUp("[Maandprijs ExtraOpvang]";"Extra Opvang";"[ExtraOpvangType]='X VM'

    for the AND part, I'd like to add the JaartalId, which is a foreign key to [Jaartabel].

    The JaartalId, can be retrieved by : =DLookUp("[Id]";"Jaartabel";"[Jaartal]= " & [Forms]![Overzicht facturatie]![cboJaar])

    Thus now I need to combine both expressions but I do not succeed ... (yet)

  5. #5
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84
    OK, got it working:

    =DLookUp("[Maandprijs ExtraOpvang]";"Extra Opvang";"[ExtraOpvangType]='X VM' AND [JaartalId]=" & DLookUp("[Id]";"Jaartabel";"[Jaartal]= " & [Forms]![Overzicht facturatie]![cboJaar]))

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Well done. Sorry - hadn't seen your earlier replies
    It wouldn't have been possible to get the correct code from your initial description alone
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Referring to Columns in a Table
    By zashaikh in forum Queries
    Replies: 10
    Last Post: 08-04-2017, 06:26 AM
  2. Replies: 2
    Last Post: 03-02-2012, 01:28 PM
  3. Referring to another table for a text box
    By hawkins in forum Reports
    Replies: 5
    Last Post: 07-05-2011, 04:14 PM
  4. Dlookup Combobox
    By zeroeu in forum Forms
    Replies: 1
    Last Post: 06-24-2011, 03:48 AM
  5. Referring to objects
    By stubbly in forum Programming
    Replies: 1
    Last Post: 10-14-2009, 09:36 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