Results 1 to 8 of 8
  1. #1
    Asma is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    11

    Unhappy Return all results in one cell/As one block

    Hi



    I'm saving email address for contacts in a database. I want to send an email to all the contacts and I need the emails to be like one block. That will make it easier by just copy and paste it in the To field in an email.

    I've got the data in a table as:
    a@b.com;
    c@d.com;
    e@f.com;

    And I need it to be as:

    a@b.com; c@d.com; e@f.com

    how can I make all results appear in the same cell not as a table

    plzzzzzz help

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Create a User Defined Function in a standard module that walks through the table and returns the concantenated string.

  3. #3
    Asma is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    11
    Quote Originally Posted by RuralGuy View Post
    Create a User Defined Function in a standard module that walks through the table and returns the concantenated string.
    Thank you so much for the idea. I understand what your saying ( I worked with java and other programming languages, but I never coded in access), but I don't know where to write the code and what to write ??
    any refrences ??

    currently all I have is a query that takes the email addresses and adds ";" to the end of each email and it returns a table.

    can you plz provide me with more details about how to do it?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    Create a User Defined Function in a standard module that walks through the table and returns the concantenated string.
    what's the word on me over with the big boys ruralguy? have I been declared insane yet? I waited like 2 months after they ousted me and took another look but Bob was still on the lookout for my IP. It only took him like 4 or 5 days to browse the new accounts and catch it.


    At any rate, here's a module for you:
    Code:
    function t

    dim emails 
    as string
    dim db 
    as dao.database
    dim rs 
    as dao.recordset

    set db 
    currentdb
    set rs 
    db.openrecordset("tablename")

    rs.movelast
    rs
    .movefirst

    emails 
    ""

    do until rs.eof

    emails 
    emails rs!fieldname " "

    rs.movenext

    loop

    rs
    .close

    set rs 
    nothing
    set db 
    nothing

    end 
    function 
    of course after this you have to throw the EMAIL string somewhere otherwise it'll just stay in memory.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    And there is always something more universal like: http://allenbrowne.com/func-concat.html

  6. #6
    Asma is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    11

    Smile

    Quote Originally Posted by ajetrumpet View Post
    what's the word on me over with the big boys ruralguy? have I been declared insane yet? I waited like 2 months after they ousted me and took another look but Bob was still on the lookout for my IP. It only took him like 4 or 5 days to browse the new accounts and catch it.


    At any rate, here's a module for you:
    Code:
    function t

    dim emails 
    as string
    dim db 
    as dao.database
    dim rs 
    as dao.recordset

    set db 
    currentdb
    set rs 
    db.openrecordset("tablename")

    rs.movelast
    rs
    .movefirst

    emails 
    ""

    do until rs.eof

    emails 
    emails rs!fieldname " "

    rs.movenext

    loop

    rs
    .close

    set rs 
    nothing
    set db 
    nothing

    end 
    function 
    of course after this you have to throw the EMAIL string somewhere otherwise it'll just stay in memory.
    That was really helpful , but I still have one last stupid question
    How to link this to my query?? and what are the choices I have to return the String Emails ??
    Now, im using a msgbox to check the output ,but I'm looking for a better way because I want to be able to copy and paste the info .

  7. #7
    Asma is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    11
    and here's the function with small editting cz I wanted to return the two optional email fields if they have something

    Function t() As String


    Dim emails As String
    Dim db As dao.Database
    Dim rs As dao.Recordset


    Set db = CurrentDb
    Set rs = db.OpenRecordset("Client Contact")


    rs.MoveLast
    rs.MoveFirst


    emails = ""


    Do Until rs.EOF


    emails = emails & rs!EmailAddress1 & "; "


    If Not (EmailAddress2 = " ") Then
    emails = emails & rs!EmailAddress2 & "; "
    End If


    If Not (EmailAddress3 = " ") Then
    emails = emails & rs!EmailAddress3 & "; "
    End If


    rs.MoveNext


    Loop


    rs.Close


    msgbox( emails)


    Set rs = Nothing
    Set db = Nothing




    End Function

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    replace
    msgbox( emails)
    with
    debug.print emails

    then run the function in VB Editor. the emails will show in "immediate window", then you can copy and paste.

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

Similar Threads

  1. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  2. Flag A Data Block
    By JohnBoy in forum Programming
    Replies: 7
    Last Post: 06-29-2010, 01:18 PM
  3. Replies: 5
    Last Post: 10-08-2009, 05:15 AM
  4. change cell color
    By bishop743 in forum Programming
    Replies: 0
    Last Post: 02-01-2009, 11:00 AM
  5. Can we post Access cell data to Excel cell properties?
    By Zethro in forum Import/Export Data
    Replies: 1
    Last Post: 12-13-2005, 08:42 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