Results 1 to 9 of 9
  1. #1
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10

    DLookup displaying #Name? when used in a form

    I am using a DLookup function to look up a value in a table and put that value in a text box. The Table BudgetTable has the following fields:
    Click image for larger version. 

Name:	BudgetTable.PNG 
Views:	13 
Size:	9.5 KB 
ID:	37706
    My DLookup code is placed in the control source of a text box and is : =DLookUp("[ActualMRC]","[BudgetTable]","[MonthNum]=12" And "[CircuitID]=" & [Forms]![subfrmBudgetInfo]![CircuitID])

    This produces a value when in a subform but when that subform is used with a parent form the textbox displays #Name?


    Any ideas?!?

  2. #2
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10
    Jeez!!! figured it out I need to add the Mainform to the string =DLookUp("[ActualMRC]","[BudgetTable]","[MonthNum]=12" And "[CircuitID]=" & [Forms]![frmSearchCircuitInfoNew]![subfrmBudgetInfo]![CircuitID])

  3. #3
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10
    Now that it displays data in the field it will not change when the record changes. Any ideas on how to get this to update?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I am surprised the expression returns anything with that incorrect syntax. There are too many quote marks. Remove the red ones.

    =DLookUp("[ActualMRC]","[BudgetTable]","[MonthNum]=12" And "[CircuitID]=" & [Forms]![frmSearchCircuitInfoNew]![subfrmBudgetInfo]![CircuitID])

    If this expression is in textbox on frmSearchCircuitInfoNew, then the forms qualifier prefix should not be needed but shouldn't hurt either.

    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
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10

    #Error

    Quote Originally Posted by June7 View Post
    I am surprised the expression returns anything with that incorrect syntax. There are too many quote marks. Remove the red ones.

    =DLookUp("[ActualMRC]","[BudgetTable]","[MonthNum]=12" And "[CircuitID]=" & [Forms]![frmSearchCircuitInfoNew]![subfrmBudgetInfo]![CircuitID])

    If this expression is in textbox on frmSearchCircuitInfoNew, then the forms qualifier prefix should not be needed but shouldn't hurt either.

    Thank you for your help June7 after making the change suggested the field now shows #Error

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    CircuitID is a number field? If it is text, need apostrophe delimiters for the parameter.

    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.

  7. #7
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10

    Fixed!

    Quote Originally Posted by June7 View Post
    CircuitID is a number field? If it is text, need apostrophe delimiters for the parameter.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    Thanks June7! I did need the apostrophe delimiters for that parameter. Do you have a resource that explains the use of ' and " that I could look at to gain a better understanding?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    No, I don't.

    When used as special character (not just normal text in field as in O'Reilly or 1.0") they must be in pairs. And alternate their use. Use quote to define begin and end of a string. Then if you need to embed delimited parameters in that string, use apostrophes (or a doubled quote - which is called 'escaping' a special character - but I find that harder to read).

    Text fields require apostrophe (or the doubled up quote) as delimiter for parameter.

    Date fields require # character.

    Number fields do not need delimiter.

    Use of apostrophe and quote characters in data can cause issue with building SQL statements in code. So if a parameter needs to use 'O'Reilly' - the SQL will choke on that extra apostrophe. Use Replace function to double the apostrophe so it will be treated as a single normal text apostrophe, not a special character, if there is a chance data can have apostrophe.

    Code:
    CurrentDb.Execute "UPDATE tablename SET LastName='" & Replace(Me.tbxLName, "'", "''") & "' WHERE ID=" & Me.tbxID
    Quote in data is even trickier. I have a database where I refuse to allow entries like found at depth 4.6" - not allowed to use quote character - spell out inches or convert to decimal feet. Somebody gets their hand slapped if they don't comply.
    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.

  9. #9
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10
    Thank you for taking the time to explain it! I appreciate all your help.

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

Similar Threads

  1. Replies: 10
    Last Post: 07-04-2015, 02:55 PM
  2. Replies: 3
    Last Post: 08-26-2014, 12:52 PM
  3. Replies: 10
    Last Post: 10-14-2013, 10:18 AM
  4. displaying a date using DLookup
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 08-25-2011, 05:24 PM
  5. Replies: 1
    Last Post: 11-07-2010, 11:04 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