Results 1 to 5 of 5
  1. #1
    Jeff123 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    5

    Beginner needs help :) MS Access query - how to format data lines into a paragraph

    I have this query:

    SELECT TOP 5 Replace([TXT],"Member","Antonio") AS Expr1
    FROM [ADHD/ODD]
    ORDER BY Rnd(Int(Now()*id)-Now()*id);

    This query selects five items from a table at random, and list these items with a name change (changes the word "member" to a different name).
    The query outputs in this format (single spaced):

    Antonio eats apples.
    Antonio drinks milk.


    Antonio watches TV.

    I would like for the query (or report) to output like this:

    Antonio eats apples. Antonio drinks milk. Antonio watches TV.

    I then make a report from this query. I am unsure if the query should be changed, or if there is certain property in the report that should be changed.
    I have honestly searched the web, but have no clue. I searched on how to use concatenate, but cannot figure it out. Any help would be GREATLY appreciated
    Thanks, Jeff

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    this function will collect all the values in the field for all records, and produce 1 string.
    use it in a text box , or query:

    Code:
    function CollectMemoFlds()
    dim sSql as string, sTxt as string
    dim rst
    
    sSql = "select * from table"
    Set rst = currentdb.OpenRecordset(sSql)
    With rst
      While Not .EOF
          sTxt = sTxt & " " & .Fields("MyField").Value & ""
         
         .MoveNext
      Wend
    End With
    
    
    CollectMemoFlds = sTxt
    set rst = nothing
    end function

  3. #3
    Jeff123 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    5
    Quote Originally Posted by ranman256 View Post
    this function will collect all the values in the field for all records, and produce 1 string.
    use it in a text box , or query:

    Code:
    function CollectMemoFlds()
    dim sSql as string, sTxt as string
    dim rst
    
    sSql = "select * from table"
    Set rst = currentdb.OpenRecordset(sSql)
    With rst
      While Not .EOF
          sTxt = sTxt & " " & .Fields("MyField").Value & ""
         
         .MoveNext
      Wend
    End With
    
    
    CollectMemoFlds = sTxt
    set rst = nothing
    end function
    Hello, thanks for your help. I tried working with what you typed, but I'm getting stumped on how to insert that into my query. The query is:

    SELECT TOP 5 Replace([TXT],"Member","Antonio") AS Expr1
    FROM [ADHD/ODD]
    ORDER BY Rnd(Int(Now()*id)-Now()*id);

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you need to build the sql for what you want in the code,


    then the query uses:
    select CollectMemoFlds([keyFld]) from table


    if you want it for 1 key ,we need to alter the code to:

    Code:
    function CollectMemoFlds(pvKey)
    dim sSql as string, sTxt as string
    dim rst
    
    
    sSql = "select * from table where [key]=" & pvKey
    Set rst = currentdb.OpenRecordset(sSql)
    With rst
      While Not .EOF
          sTxt = sTxt & " " & .Fields("MyField").Value & ""
         
         .MoveNext
      Wend
    End With
    
    
    CollectMemoFlds = sTxt
    set rst = nothing
    end function

  5. #5
    Jeff123 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    5
    ok, I will be working on that. Thanks for your time!

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

Similar Threads

  1. Replies: 7
    Last Post: 03-05-2018, 02:16 PM
  2. Replies: 3
    Last Post: 10-11-2016, 10:53 PM
  3. Replies: 6
    Last Post: 07-31-2014, 12:53 PM
  4. Replies: 5
    Last Post: 02-16-2013, 07:57 AM
  5. Replies: 1
    Last Post: 09-07-2011, 01:56 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