473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Taking all values from a column and putting them together with a "; " separator

7 New Member
It seemed simple at the time...

Ask for their email addresses, then when I have a list of people to contact, I can make my Access database spit the addresses out for me...

Here's my quandry:
I have a table (related to other tables in my database)that simply lists [Name][EmailAddress] and [ContactNumber]. I use a few queries to sort everything out and end up with usually about 5-10 people listed that need an email to remind them of delinquent entries. I have an Outlook template all made up and ready - and I figured I could grab the email addresses pretty easily (never tried this before - but hey - Access should make this part easy, right?)

After learning that there doesn't seem to be a built in function for this, I figured maybe I should try to send these addresses to a textbox in my form (hidden from view) and just use vba to plug that value into the To: line...

After a LOT of frustration, I am stumped. I know it's probably something simple - but for the life of me, I cannot figure this out! All of the threads I read are either for how to build an email in vba (which I already can do) or how to concatenate different values on a row...

I need (I think) to be able to concatenate the values from one COLUMN in my query into a textbox, and I can carry it from there.

(My SQL and VBA skills are amateur, so if you have the time to respond, please explain it to me like I'm a 10 year old!)

Thanks in advance for your help!

Dave
May 20 '11 #1
11 2145
hype261
207 New Member
So basically you are going to have to run some VBA to get this to work, but it shouldn't be that hard.


First you are going to have to open a recordset to get all the emails. Then you are going to have to loop through the recordset.

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim rcd as DAO.recordset
  3. dim emailAddress as string
  4.  
  5. set rcd = CurrentDB.OpenRecordset("SELECT EmailAddress FROM SomeTable")
  6.  
  7. do until rcd.eof
  8. emailAddress = emailAddress & rcd!EmailAddress & "; "
  9. loop
  10.  
  11. 'Make sure we have some email addresses
  12. if(Len(emailAddress) > 0 )
  13.  
  14. 'Do something interesting
  15.  
  16. Else
  17.  
  18. 'Report to user no email addresses
  19.  
  20. End if
  21.  
This should get you started.
May 20 '11 #2
Mc1brew
4 New Member
Does t-sql work in access? I'v seen this done with an elaborate use of coalesce and stuff, though I've seen, I could not tell how to repeat.
May 21 '11 #3
Lysander
344 Recognized Expert Contributor
Interested in the question. Fairly easy to do in code but can it not be done via PIVOT or TRANSFORM? I can't work out how, but it seems like it should be possible.
May 21 '11 #4
hype261
207 New Member
T-SQL doesn't work with access (I really wish it would). Also on my list would be stored procedures, but none the less.

I suppose you could do a combination of a VBA function inside the SQL.
May 21 '11 #5
NeoPa
32,557 Recognized Expert Moderator MVP
Check out Combining Rows-Opposite of Union. It's not perfect but fundamentally does the job.
May 21 '11 #6
Dave DeSteno
7 New Member
I thank you all for the replies.

Sadly, I still cannot seem to make this work.

I'll keep plugging along - it's gotta break eventually for me, right?

I really would need it spelled out for me, I suppose - I wasn't sure what to do with the code above from hype261. Sorry to be dense! If someone has the time to hold me hand through this, fantastic - if you don't, that's fine as well.
The query name I need the info from is "qryRespCount2" and the field is "ResponsibleEmail"
I launch a form that runs 2 queries (qryRespCount1 and qryRespCount2) These in turn give me a list of names (responsible parties that have yet to sign off on jobs) and the count of open jobs per person - that display on a continuous form. My goal was to have a command button at the bottom of that form that would open an Outlook email (or better yet, an Outlook Template) and populate the "To:" field on that email with all of the addresses of the people with delinquent jobs.

Again, if someone has the time to spell it out, I thank you in advance. If not, thank you for your help up until now!

Dave
May 26 '11 #7
NeoPa
32,557 Recognized Expert Moderator MVP
Dave, I will see what I can do to help you through this. No promises at this time though.
  1. What's the name of the form you want this data to display on?
  2. What is the SQL of the recordsource of this form?
  3. What is the name of the control on the form where you would like the list to display?
May 26 '11 #8
Dave DeSteno
7 New Member
Okay - I was off on my Query/Form names slightly...
They are: ResponsibleCountQuery1 and ResponsibleCountQuery2 (I know - this was BEFORE I read about normalization)
The field name is still [ResponsibleEmail]

1. Form name to display data: ResponsibleCountForm1

2. Here's the SQL for the recordset:
SELECT ResponsibleCountQuery2.Responsible, ResponsibleCountQuery2.CountOfResponsible, ResponsibleCountQuery2.ResponsibleEmail, ResponsibleCountQuery2.RoundDate
FROM ResponsibleCountQuery2;

This is a continuous form - the text box I want to write to is in the Form Footer. (again, if this is not a good plan, let me know!)

3. Text24 (on ResponsibleCountForm1 - in the footer)
I would like the values displayed (I guess) in a text box on the very same form - ultimately I want to use SendObject - or better yet, plug it into the "To:" line on an outlook template... SendObject is UGLY when it sends out.

There has to be a better way, right?

The queries take the responsible people, and give me a count of who still has how many jobs delinquent. I then want to generate an email with the click of a button [Command26] to only the people listed them reminding them about it. (yeah - I'm not making friends around here...)

Thanks in advance
Dave
May 27 '11 #9
NeoPa
32,557 Recognized Expert Moderator MVP
Well, this is somewhat different from what I expected, but you have answered the questions clearly so let's see where we can go with it. I'm no longer of the opinion that my previous idea will help you much.

As an alternative, it seems we would probably be looking at deciding on a trigger, and developing some code to determine the value when triggered.

There are many Form based events to choose from, but my best guess would be the Load event would suit you best for this.

At that point the code could process through the recordset concatenating all the values together separated by "; "s. As there is no need to move through the Recordset on the form itself, the .RecordsetClone property is probably the one to use.

The code below illustrates the kind of routine you're looking for :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5.     Dim strList As String
  6.  
  7.     With Me.RecordsetClone
  8.         Do While Not .EOF
  9.             strList = strList & "; " & .ResponsibleEmail
  10.             Call .MoveNext
  11.         Loop
  12.         Me.Text24 = Mid(strList, 3)
  13.     End With
  14. End Sub
May 27 '11 #10
Dave DeSteno
7 New Member
This works beautifully! I owe you a pint!

Thank you. Thank you. Thank you!
May 27 '11 #11
NeoPa
32,557 Recognized Expert Moderator MVP
I don't mind if I do :-D

You're welcome of course.
May 27 '11 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

12
1512
by: Stéphane Ninin | last post by:
Hi all, This is not the first time I see this way of coding in Python and I wonder why this is coded this way: Howto on PyXML (http://pyxml.sourceforge.net/topics/howto/node14.html) shows it...
3
10016
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
81
7222
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
18
4830
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing)...
22
22235
by: campbellbrian2001 | last post by:
Thanks in Advance! ... I have two textboxes: 1 is visible (and gets its value based on the invisible textbox and displays either "Male" or "Female", and needs to display either male of female based...
3
1970
by: MLH | last post by:
If I run ?", ","" in the immediate window, I get a comma followed by 13 spaces. It is difficult for me to understand this.
5
3216
by: Denis Petronenko | last post by:
Hello, how can i read into strings from ifstream? file contains values in following format: value11; val ue12; value 13; valu e21;value22; value23; etc. i need to read like file >string,...
21
7796
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
1
2829
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
3872
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.