I have a query I am using to create an email. I have a situation where for one location I have three people that have to receive the information. In the query it creates three records however in my code it only recognizes the first person and does not pick up the other two. How can I get either the code or the query to combine that field for all three records.
Code to pull results of one field with multiple answers
Collapse
X
-
My code is not the problem. I pulls the field in just fine. It is as follows:
Code:Me![Email] _
Does this explanation help?Comment
-
If you have 3 records then you will need to send out 3 emails. You go through the recordset with a loop until you get to the last record. For each new record, you process the email sending code.
And as Neo said, actually posting either the query or the processing code is going to make your life easier and get a much quicker response.Comment
-
I am sorry to have upset you however consider that I am still new at this.
I don't know if this will help or not. I understand I need some type of looping but just can't figure out how to get there.
My tables are as follows: One (Contacts) holds the contact persons information the other table is linked by the Contacts ID and Location number which identifies what location they are responsible for. One location can have three contact people.
Here is my code:
Code:Private Sub EmailReport_Click() On Error GoTo Err_EmailReport_Click Dim Loc_No As String Dim stLinkCriteria As String stEmailTo = DLookup("[MailingsEMail]", "[Facilities]", "[Loc No] = '" & Me![Loc No] & "'") stLinkCriteria = "[Loc No]=" & "'" & ("[Loc No]=Query![qselReportDistForm]![Loc No]") & "'" DoCmd.SendObject acSendNoObject, stDocName, , stEmailTo, ReportMailingCC, , _ Me![MailingEmailTextSubjectLine] & "," & " " & DLookup("[Client Name]", "[Facilities]", "[Loc No] = '" & Me![Loc No] & "'") & "," & " " & DLookup("[Physical City]", "[Facilities]", "[Loc No] = '" & Me![Loc No] & "'") & "," & " " & DLookup("[Physical State]", "[Facilities]", "[Loc No] = '" & Me![Loc No] & "'") & "," & " " & DLookup("[Physical Country]", "[Facilities]", "[Loc No] = '" & Me![Loc No] & "'") & " " & "Loc No" & " " & Me![Loc No], _ "The following Facility Specific Copies personel listed needs to be moved to the CC" & " " & Me![Email] _ & vbCr & " " _ & vbCr & " " _ & vbCr & Me![MailingEmailText] Exit_EmailReport_Click: Exit Sub Err_EmailReport_Click: MsgBox Err.Description Resume Exit_EmailReport_Click DoCmd.Close End Sub
Comment
-
If Me.Email can possibly have multiple records, then surely we have a logic problem. I'm having to read between the lines somewhat, but I suspect the form will only show one of these at a time. That makes life a little more complicated. We either need to design things such that a ";" separated string is available on the form, or we could possibly look at opening a DAO.Recordset in the code to access each in turn within the routine.
Have a look at Basic DAO recordset loop using two recordsets for some basic use of Recordset coding. We can get into more detail if and when required, but this may point you in the right direction.Comment
-
Thank you I will and get back to you. I may not have explained this very well and apologise for that. I have to have two tables one is the Location and a location can have multiple safety people assigned that have their own table with their personal information. In sending an email for a location I have to pull in multiple safety people. You are correct in that it will only pull in the first one it sees. As I mentioned I will review this informtion you provided and let you know. ThanksComment
Comment