Results 1 to 4 of 4
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    DLookUp on form control not working for some strange reason

    I came across an error I haven't seen before. I have a DLookUp function on a control on a form that works just fine. As is shown here

    =DLookUp("Type","ReferenceT","MetricID = '" & [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetricID] & "'")

    So, it looks up the Field "Type" form the table "ReferenceT" and then finds the record relating to a particular ID. This works and it shows the value on the screen.

    HOWEVER,

    when I use the same function and instead change the field to a particular field, it stops working..

    =DLookUp("Sub-Type2","ReferenceT","MetricID = '" & [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetricID] & "'")

    In fact, what happens is that the control flashes on the screen uncontrollably and doesn't stop.

    I try a different field name

    =DLookUp("Definition","ReferenceT","MetricID = '" & [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetricID] & "'")



    and it works again.

    Now, the kicker here is that I have another field name "Sub-Type1" and try that, and AGAIN, it doesn't work.

    My thoughts are that the issue lies in the defining of the field name. That DLookUps do not allow field names to take on this naming procedure with "-" or numbers.

    Does anyone know if this is true? And if that is the case, then how do you get around this issue without having to rename your fields?

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Not strange at all. The hyphen is minus sign. The expression is trying to calc two non-existent fields. Try enclosing the field name in [].

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Ah, you are correct. The square brackets helped.

    Thanks!

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    =DLookUp("Type","ReferenceT","MetricID.....
    Also bear in mind that 'Type' is an access reserved word and using it will cause issues. Putting it in square brackets may solve the problem in some cases, but there are others where square brackets won't help and you will get an error you will spend hours trying to resolve.

    here is a link to access reserved words

    https://support.office.com/en-in/art...7-da237c63eabe

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

Similar Threads

  1. Dlookup from another table in form not working
    By ascool_asice in forum Forms
    Replies: 6
    Last Post: 01-04-2015, 03:39 AM
  2. Replies: 4
    Last Post: 04-22-2014, 12:36 PM
  3. Replies: 10
    Last Post: 12-27-2013, 02:54 PM
  4. Replies: 3
    Last Post: 07-18-2013, 12:23 PM
  5. Dlookup as control source on continuous form.
    By Ramun_Flame in forum Programming
    Replies: 4
    Last Post: 10-24-2012, 10:26 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