Results 1 to 7 of 7
  1. #1
    steezy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3

    Issue with seemingly simple DLookUp()

    Hello all,



    I've been spending most of the day setting up a new database in Access and in one of the first forms I'm creating, I'm having an issue.

    For some reason, this expression I'm using as a control in a textbox simply will not return anything other than null values.

    (For background, I have a number of different types of events in table EventTypes. Each record in the table has an integer for Days. In this instance, when someone selects the title of the event in the combo box above, I want this text box to simply pull the Days value.)

    Code:
    =Nz(DLookUp("[Days]","[EventTypes]","[Title]='" & [Forms]![New Event]![EventDesired] & "'"),0)
    I've tried a number of different ways to pull this info, and it simply returns zero every time. Where am I going wrong? I've been searching for hours and getting nowhere.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    This might be another option:

    BaldyWeb - Autofill

    Offhand, the syntax of the DLookup() looks correct, presuming Title is a text field. Have you confirmed what the form control contains?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    First, have you used Lookups in tables? I NEVER do that http://access.mvps.org/access/lookupfields.htm

    Second, what data type is EventDesired?

    Is this field on the same form as the DLookup expression textbox? Try:

    =Nz(DLookUp("[Days]","[EventTypes]","[Title]='" & [EventDesired] & "'"),0)

    Why do you need to use DLookup()? Usually better methods - include table in RecordSource or reference combobox column.
    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.

  4. #4
    steezy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    This might be another option:

    BaldyWeb - Autofill

    Offhand, the syntax of the DLookup() looks correct, presuming Title is a text field. Have you confirmed what the form control contains?
    Thanks for the link Paul, I had just found it myself. I'm going to try that.

    Quote Originally Posted by June7 View Post
    First, have you used Lookups in tables? I NEVER do that http://access.mvps.org/access/lookupfields.htm

    Second, what data type is EventDesired?

    Is this field on the same form as the DLookup expression textbox? Try:

    =Nz(DLookUp("[Days]","[EventTypes]","[Title]='" & [EventDesired] & "'"),0)

    Why do you need to use DLookup()? Usually better methods - include table in RecordSource or reference combobox column.
    Yes, I have used lookups in tables... but the field Title in the EventTypes table is not a lookup. Being a newbie, I didn't realize that wasn't good practice. What should I be doing instead? (And just to answer the question, EventDesired is a text string.

    EDIT: Also, June7's modified expression didn't work any differently.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Instead of lookups in tables, build comboboxes on forms.

    What is the combobox RowSource? Is the actual value of the combobox an ID or the event description?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  6. #6
    steezy is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3
    Here's the Row Source. The value in the combobox is Title, not the ID.

    Code:
    SELECT [EventTypes].[EventTypeID], EventTypes.[Title] FROM EventTypes;
    I may take you up on the offer to send the db for analysis.

    Thanks,
    Sam

    EDIT: I actually have a larger issue with this file, but I will start a new thread for it eventually.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    The EventTypeID field is the first field in the RowSource. If the BoundColumn is set to 1 then the actual value of the combobox is EventTypeID, not Title. This would explain why the DLookup criteria is not working. Even though EventDesired is a text field, if the BoundColumn is set to 1 then the EventTypeID is saved, not Title.

    =Nz(DLookUp("[Days]", "[EventTypes]", "[EventTypeID]=" & [EventDesired]),0)

    Now this will possibly generate "datatype mismatch" error, if EventTypeID is a number field and EventDesired is text field, even if it is storing digit values, it's still a text field.
    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.

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

Similar Threads

  1. Recover a seemingly corrupted form
    By GraeagleBill in forum Forms
    Replies: 13
    Last Post: 08-21-2014, 06:40 PM
  2. Help with (seemingly) simple filter
    By TCWAptar in forum Programming
    Replies: 11
    Last Post: 08-11-2014, 11:21 AM
  3. Semi-Nube Simple DLookup Issue - Help?
    By bimcompu in forum Programming
    Replies: 5
    Last Post: 07-26-2013, 07:21 AM
  4. Help With Simple Error on Dlookup and Insert To
    By asdaf3814 in forum Programming
    Replies: 9
    Last Post: 08-09-2012, 10:50 AM
  5. Simple issue?
    By Patience in forum Access
    Replies: 8
    Last Post: 05-29-2010, 07:02 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