Results 1 to 11 of 11
  1. #1
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17

    Dlookup Help

    Hello, I have a form (f_on_farm_entry) where I use a combo box to select a county. I am trying to get a text-box on the same form to display the county code for the county that is selected. The County Code is which is stored in another table ("County Code") in a column named CoNum


    Here is the expression I am trying to use: =DLookUp("CoNum","County Code","County=" & Forms![f_on_farm_entry].cbo_county)

    I keep getting an error an was hoping someone could see what I was doing wrong.



    Thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You should not use names with spaces. If you do put them in brackets.
    "[country codes]"

  3. #3
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17
    Thank you. I am still getting an error though. I changed County Code to County_Code. Here is what I am using now:

    =DLookUp("CoNum","County_Code","County=" & [Forms]![f_on_farm_entry].[cbo_county])

    here is my county code table, and I want "CoNum" displayed in the text box:

    ID County CoNum
    6 ALAMEDA 06001-

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You 1st had a space in the table,
    now you have an underscore.
    which is it?

    if the table has a space, YOU MUST USE BRACKETS.

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Since County looks like a text field, I think you need Text Qualifiers around the value you are returning from your Form, i.e.
    Code:
    =DLookUp("CoNum","County_Code","County='" & [Forms]![f_on_farm_entry].[cbo_county] & "'")

  6. #6
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17
    Sorry, I was meaning to clarify that I changed the table name to remove the space to an underscore

  7. #7
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17
    Thank you Joe, I used what you provided, but now the box where I want the result is empty instead of stating "error". Sorry I am trying to learn this stuff and am obviously not a database person.

  8. #8
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If possible, it might be best to upload your database (or at least a scaled down version of it), for analysis.

  9. #9
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17
    Here is a very basic version of it, but the table structure for these two tables should be the same. I had to put in a zip file
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Weird thing about domain aggregate functions is they will accept table name with space without brackets. I also recommend not to use spaces nor punctuation/special characters (underscore only exception) in names. Nor reserved words as names.

    However, DLookup is not necessary. Change the combobox properties:

    RowSource: SELECT [ID], [County], [CoNum] FROM County_Code ORDER BY [County];
    ColumnCount: 3
    ColumnWidths: 0";1";0

    Then expression in textbox: =[cbo_county].[Column](2)
    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.

  11. #11
    www is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    17
    Quote Originally Posted by June7 View Post
    Weird thing about domain aggregate functions is they will accept table name with space without brackets.

    However, DLookup is not necessary. Change the combobox properties:

    RowSource: SELECT [ID], [County], [CoNum] FROM County_Code ORDER BY [County];
    ColumnCount: 3
    ColumnWidths: 0";1";0

    Then expression in textbox: =[cbo_county].[Column](2)

    That worked perfect, Thanks!

    I also built on that to concatenate with he APN on the form and got what I wanted a county code with he apn =[cbo_county].[column](2) & [APNs]

    Thanks again,

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

Similar Threads

  1. Help With DLookup
    By NickS in forum Access
    Replies: 20
    Last Post: 12-17-2017, 11:49 AM
  2. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  3. Like in Dlookup
    By msp4422 in forum Programming
    Replies: 3
    Last Post: 02-19-2013, 04:02 PM
  4. DLookUp Help
    By ThaGreenMoose in forum Forms
    Replies: 10
    Last Post: 06-15-2011, 12:08 PM
  5. DLookup help
    By denners05 in forum Access
    Replies: 1
    Last Post: 06-11-2011, 12:55 PM

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