philbertson
i'm just here
- Local time
- Today, 08:55
- Joined
- Jan 27, 2005
- Messages
- 15
below is the code i have to send emails based upon an event.
Dim db As Database
Dim requestqry As Recordset
Dim objoutlook As New Outlook.Application
Dim objmessage As MailItem
Dim strSQL As String
Dim Body As String
Dim email As String
Set db = CurrentDb()
Set requestqry = db.OpenRecordset("finemail")
While Not requestqry.EOF
If Not IsNull(requestqry("fin email")) Then
Set objmessage = objoutlook.CreateItem(olMailItem)
With objmessage
.To = requestqry("fin email")
.Subject = "Employee Request Waiting Approval"
.Body = Body
.Send
End With
End If
requestqry.MoveNext
Wend
requestqry.close
Set requestqry = Nothing
Set objoutlook = Nothing
Set objmessage = Nothing
The body copy of the message is omited for it is of no importance here. Anyway. The code finds the proper email, send the message and all is well right? Wrong.
It gets its data based upon a query. the problem is that it send a email for every record in the query. if i set the query to show only the top record, it sends the top record only.
What i need is to send the record that is currently being viewed/edited on the form where the control button is that triggers this code.
Is this a code problem, a query problem and how do i fix it.
Phil
Dim db As Database
Dim requestqry As Recordset
Dim objoutlook As New Outlook.Application
Dim objmessage As MailItem
Dim strSQL As String
Dim Body As String
Dim email As String
Set db = CurrentDb()
Set requestqry = db.OpenRecordset("finemail")
While Not requestqry.EOF
If Not IsNull(requestqry("fin email")) Then
Set objmessage = objoutlook.CreateItem(olMailItem)
With objmessage
.To = requestqry("fin email")
.Subject = "Employee Request Waiting Approval"
.Body = Body
.Send
End With
End If
requestqry.MoveNext
Wend
requestqry.close
Set requestqry = Nothing
Set objoutlook = Nothing
Set objmessage = Nothing
The body copy of the message is omited for it is of no importance here. Anyway. The code finds the proper email, send the message and all is well right? Wrong.
It gets its data based upon a query. the problem is that it send a email for every record in the query. if i set the query to show only the top record, it sends the top record only.
What i need is to send the record that is currently being viewed/edited on the form where the control button is that triggers this code.
Is this a code problem, a query problem and how do i fix it.
Phil