Access 2010 - DLoolup Show Results Values in Texbox on its own line multiple columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gcoaster
    New Member
    • Sep 2007
    • 117

    Access 2010 - DLoolup Show Results Values in Texbox on its own line multiple columns

    Hello Group
    what i am trying to occomplish something i cannot find no matter how hard i search! maybe i am not wording it right.

    I would like to use DLookup to show results values from a table and display in a unbound textbox on a form. the results from each column in the table need to be on seperate lines, a break if you may. Here is the code I have so far.

    Code:
    txtKeywords = DLookup("colKeyword", "tblKEYWORDS", "cboCategory = '" & txtcategories & "'")

    In colKeyword Column In tblKEYWORDS table match what i select in cboCategory Combo drop down box and populate txtcategories textbox on form

    What I would like to do is show All colKeyword results in textbox [txtcategories] and display each result on its own line!

    example

    entry1
    entry2
    entry3
    entry4


    Thank you for your time
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    I'm a little confused by your question. Are you doing multiple DLookups and you want the results from each to be on a separate line? DLookup can only return a single value, but it sounds like you only have one DLookup. If you are doing multiple DLookups, then you might try using a recordset instead as domain functions (DLookup, Dcount, etc.) are resource intensive and can slow your program down with excessive use.

    So, no matter how you are getting the different lines of information (or entries from your example), the way to put them are their own line is to concatenate the vbCrLf constant into the string. Something like this:
    Code:
    Me.txtCategories = "Entry 1" & vbCrLf & "Entry 2" & vbCrLf & "Entry 3"
    
    Produces...
    
    Entry 1
    Entry 2
    Entry 3
    So the question now becomes how are you getting your bits of entry information.

    Comment

    • gcoaster
      New Member
      • Sep 2007
      • 117

      #3
      Hello Seth,
      Thank you for your time.

      I guess I am trying to do a =DLookup to pull out a columns data in a table that matches a particular category and populate a unbound textbox on a form - each value on its own line.

      For instance if I select "Bytes" from combobox
      then the dlookup would show me all of the entries in the table that have the category "Bytes" and then populate the textbox.

      result would be in the txtbox

      Database Geniuses
      access databases
      Database Heroes



      Thank You

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        DLookup cannot pull an entire column that matches your criteria. It will only return the value in the field specified for the first record that it finds that does match your criteria. It sounds like you would benefit from using a recordset and then looping through it to add the different records into the textbox. Then again, it may be simpler to just use a subform, unless there is a reason that you need all your data in one textbox (which won't allow edits to be saved).

        Comment

        • gcoaster
          New Member
          • Sep 2007
          • 117

          #5
          Thanks Seth, Now i understand DLookup
          Dont need a subform, no need to edit the data. Nothing is simple in Access!

          Ok, A recordset and then looping through it

          Comment

          Working...