Results 1 to 13 of 13
  1. #1
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55

    DLookup error

    Hello and thank you in advance for any attention this post may receive.

    So I want a text box to populate based on what is in a combo box. Both text and combo box values come from the same table.

    Table = Fauna


    Combo Box = "Animal"
    Text Box = "AnimalGenre"

    Combo Box RowSource =SELECT [ID], [Animal] FROM Fauna ORDER BY [Animal];
    Text Box Control Source =DLookUp("Animal Genre","Fauna","ID=" & [Animal])

    Combo Box is working fine. Text box contains #Name? error.

    Cheers Nadine

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Don't use DLookup.

    Include the Animal Genre field as another column in the combobox RowSource. Then expression in textbox can refer to that column by its index. Index begins with 0.

    =[combobox name].[Column](2)

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention. If used, enclose name in [].
    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
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,046
    Hi Nadine,

    your combobox can work with the control source = DLookUp("[Animal Genre]","Fauna","ID=" & [Animal]) if [Animal] is a number field.
    If [Animal] is a text field it should read: DLookUp("[Animal Genre]","Fauna","ID=""" & [Animal] & """")

    greetings
    Noëlla

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    'Animal' is the name of combobox and its value is the ID which I presume is a number field.

    Again, DLookup is not needed and performs slower than the suggested alternative.
    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
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Thank June and Noella for your advice

    June I am not sure how to include the Animal Genre field as another column in the combobox RowSource.

    Thank you for your help

    Nadine

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    RowSource: SELECT [ID], [Animal], [Animal Genre] FROM Fauna ORDER BY [Animal];

    ColumnCount: 3

    ColumnWidths: 0;0.5;0.5
    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
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Hello june

    Thank you for your time. So I did what you suggested and it is working a treat in the table only for the 'Animal' column only.

    I am not sure what is going on with the form now because it is only giving me a number selection (ID).

    TABLE - Fauna
    Column - Animal
    Data Type - Number
    Display Control - Combo Box
    Row Source Type - Table/Query
    Row Source - SELECT [ID], [Animal], [Animal Genre] FROM Fauna ORDER BY [Animal];
    Bound - 0
    Column - 3
    Width - 0;2.5;0
    Limit to List - Yes
    Multiple Values - No
    List Edits - No
    Show only Row Source - No

    FORM - Capture
    Name - Animal
    Selection Type - Combo Box
    Control Source - Animal
    Row Source - SELECT [ID], [Animal], [Animal Genre] FROM Fauna ORDER BY [Animal];
    Row Source Type - Table/Query
    Bound Column - 0

    So if the parameters for the table and form field 'Animal' are the same I should only be able to select the text name from the list and not the IDNumber right?

    The auto-populating 'AnimalGenre' field based on the 'Animal' selection is not working either.

    TABLE - Fauna
    Column - AnimalGenre
    DataType - Text
    Display Control - Text Box


    FORM - Capture
    Name - AnimalGenre
    Selection Type - Text Box
    Control Source - =[Animal].[Column](2)
    Text Format - Plain Text

    June what have I done wrong?

    Thank you again for your time and help.

    regards Nadine

  8. #8
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Hello june

    Please excuse my incompetence......I know why the ID was all I could select on the form.......because I told it that is what I wanted to select by saying SELECT [ID],

    All else is still not working for me.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Why save Genre to table? That is duplicating data. The Genre can always be retrieved in a query that joins tables.

    Saving the Genre into record will require code (macro or VBA) in some event.
    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.

  10. #10
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    OMG June that is so right......and so obvious now that it has slapped me in the face.

    Thank you June.

    Have a great day!

  11. #11
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Hello June

    So now I have built a new access db and i have used your above formula in much the same way only this time i want the text box ([combobox name].[column](2) value to appear in the table 'ImprovementIdeas' when I save it because this data will be exported for analysis. The lookup table is 'ProductUnit'

    TABLE - ImprovementIdeas
    Field - Product (Number)
    Field - Unit (Text)

    TABLE - ProductUnit
    Field - ProductType (Number)
    Field - UnitType (text)

    FORM - CaptureData
    Field - txtProduct (ComboBox)
    ControlSource - Product
    RowSource - SELECT [ProductType], [UnitType] FROM ProductUnit ORDER BY [ProductType];
    Field - txtUnit (text)
    ControlSource - =[txtProductType].[Column](2)

    Not sure how to do this using your formulas. i had thought of using IIF in along winded way but I know there has to be a smarter way.

    Cheers....Nadine

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    There is no Column(2) in that RowSource. Column index begins with 0. So the first column is index 0 and the second is index 1.

    Why do you need to save UnitType into ImprovementIdeas? Aren't you saving the ProductType number? To export data, build a query that includes both tables. This will make all related data available.
    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.

  13. #13
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    Thank you June.

    I built the query and it is doing exactly what i want it to.

    Thank you once agan.

    Nadine

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

Similar Threads

  1. Dlookup error
    By Risto85 in forum Programming
    Replies: 7
    Last Post: 02-25-2015, 11:06 AM
  2. DLOOKUP #Error
    By neo651 in forum Forms
    Replies: 6
    Last Post: 12-12-2012, 12:54 PM
  3. DLookup Error
    By uncletreetrunk in forum Programming
    Replies: 5
    Last Post: 07-16-2012, 08:33 PM
  4. Error in Dlookup?
    By cindytan in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 02:40 AM
  5. DLookup error
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 08-25-2010, 07: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