Auto Email Help

A

Apprentice

I've been fighting this code for way too long, can someone help? Trying to
send an email from access and it hangs on this line:

Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

I have DAO Library referenced and can't get past this line

Private Sub Form_Close()
Me.Dirty = False
Dim db As Database
Dim rs As DAO.Recordset
Dim ToVar As String
Dim sql As String
sql = "SELECT EmailAddress FROM %Staff " & "Where StaffMember Like '" &
Me.ActivityLead & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

Do Until rs.EOF
ToVar = ToVar & rs!EmailAddress & ";"
rs.MoveNext
Loop

DoCmd.SendObject acSendNoObject, , , ToVar, , , "New Activity Assignment",
"A new Activity has been assigned to you in the Review Tracker", True


End Sub
 
P

Pendragon

What is the error message? Have you tried dropping the dbOpenSnapshot and
simply having Set rs = db.OpenRecordset(sql)? All of my code with recordsets
is simply either a coded Select statement or a string variable (like yours)
and then manipulate the data as you have done.
 
S

Stuart McCall

Apprentice said:
I've been fighting this code for way too long, can someone help? Trying
to
send an email from access and it hangs on this line:

Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

I have DAO Library referenced and can't get past this line

Private Sub Form_Close()
Me.Dirty = False
Dim db As Database
Dim rs As DAO.Recordset
Dim ToVar As String
Dim sql As String
sql = "SELECT EmailAddress FROM %Staff " & "Where StaffMember Like '" &
Me.ActivityLead & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

Do Until rs.EOF
ToVar = ToVar & rs!EmailAddress & ";"
rs.MoveNext
Loop

DoCmd.SendObject acSendNoObject, , , ToVar, , , "New Activity Assignment",
"A new Activity has been assigned to you in the Review Tracker", True


End Sub

If this:

%Staff

isn't just a typo, then it may be the problem. Try this:

Create a new query
Include the %Staff table
Add all the fields
Close and save the query as qryStaff
Use qryStaff instead of %Staff in your sql
 
A

Apprentice

Thanks to both Pendragon and Mr. McCall, I used both suggestions and its
ticking perfect now. Thanks alot! Here is the completed code for others:

Private Sub Form_Close()
Me.Dirty = False
Dim db As Database
Dim rs As DAO.Recordset
Dim ToVar As String
Dim sql As String
sql = "SELECT EmailAddress FROM AutoEmailQuery" & "Where StaffMember Like '"
&
Me.ActivityLead & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql)

Do Until rs.EOF
ToVar = ToVar & rs!EmailAddress & ";"
rs.MoveNext
Loop

DoCmd.SendObject acSendNoObject, , , ToVar, , , "New Activity Assignment",
"A new Activity has been assigned to you in the Review Tracker", True


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top