Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    35

    Unanswered: Dlookup from a table

    I have a table which I would like one of its field to be displayed in a textbox from a table.
    Ive tired the DLookup and no matter what I just get #Name? in the box, is my syntax wrong ??
    Code:
    = DLookup("[SUNDAY]", "Totals", "[TYPE]='GENERAL'")
    = DLookup("[Totals]![SUNDAY]", "[Totals]", "[Totals]![TYPE]='GENERAL'")
    I’ve tired the above statements

  2. #2
    Join Date
    Mar 2010
    Posts
    88
    If your table is called "Totals" and you have fields in the table called "SUNDAY" and "Type" then how about

    dlookup("Sunday","Totals","Type='General'")

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    assuming that you have a table called 'Totals' and it has a column called 'SUNDAY' and a column called 'TYPE' that should work

    there is no need to include the table name if its coming from one table
    there is no need to include the square brackets if the column and or table name don't include spaces
    the separator between table and column names should be a '.'
    eg
    table.columnname not table!columnname

    = DLookup("SUNDAY", "Totals", "TYPE='GENERAL'")

    if you are getting #name that suggests you have mistyped somethign or included a column / table that doesn't exist

    given that you have a table called 'totals', a column called 'sunday' I fervently hope neither exists as at first glance it looks like a table that violates normalisation
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If the name of the table is Totals, the name of the column from where you want to retrieve the data is SUNDAY and the name of the column that must contain the word GENERAL is TYPE, then the proper syntax is:
    Code:
    Me.MyTextBox.Value = DLookup("SUNDAY", "Totals", "TYPE = 'GENERAL'")
    Have a nice day!

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In addition to everything else, you need rename the Field named 'Type' as 'Type' is a Reserved Word in Access and using it as an Object or Field name can cause all kinds of problems!

    'General' is also a Reserved Word, but is being used as a Value here, not as a name, which is, of course, all right!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •