Solved Part 2 of Email from Record Searches (1 Viewer)

NearImpossible

Registered User.
Local time
Today, 08:20
Joined
Jul 12, 2019
Messages
225
Since the first issue was resolved, I started a 2nd thread. Please feel free to merge the two if warranted


I would like to group the emails per facility,i.e.

Facility 1 - Test@email.com; Test2@email.com
Facility 3 - Test3@email.com; Test4@email.com; Test5@email.com

so I setup the following test:

Code:
    Dim rs As Recordset
    Dim rs2 As Recordset
    Dim f As String
    Dim e As String

    Set rs = CurrentDb.OpenRecordset("Select * from [FacilityMXEmail]'", dbOpenDynaset, dbSeeChanges)
    
            While Not rs.EOF
                f = rs("[Facility Name]")
                      MsgBox f
                
                    Set rs2 = CurrentDb.OpenRecordset("Select * from [FacilityMXEmail] where [Facility Name] ='" & f, dbOpenDynaset, dbSeeChanges)
                        While Not rs2.EOF
                            e = e & rs2("[Email]") & "; "
                            MsgBox e
                            rs2.MoveNext
                         Wend
                        
                 rs.MoveNext
            Wend

However when I run it, I get Syntax error in string in query expression '[Facility Name] = 'Facility 1'.

Again, here is the table I am using

Facility NameEmailmWeekmDaymTime
Facility 1test@mail.com4thFriday1am
Facility 1test2@mail.com4thFriday1am
Facility 3test3@mail.com4thFriday12pm
Facility 3test4@mail.com4thFriday12pm
Facility 3test5@mail.com4thFriday12pm
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:20
Joined
Aug 30, 2003
Messages
36,125
You need to close the quote around the value:

Set rs2 = CurrentDb.OpenRecordset("Select * from [FacilityMXEmail] where [Facility Name] ='" & f & "'"
 

NearImpossible

Registered User.
Local time
Today, 08:20
Joined
Jul 12, 2019
Messages
225
You need to close the quote around the value:

Set rs2 = CurrentDb.OpenRecordset("Select * from [FacilityMXEmail] where [Facility Name] ='" & f & "'"

Wow, so I thought I did that but it kept saying Expected: list separator or ), turns out I wasn't putting the first quote on there and only had & '"

Thanks again !!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:20
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

Users who are viewing this thread

Top Bottom