When i click the Cummond Button it should email my query ('qryToday')
information as body to the list of people which has mentioned in tblNameList,
and the mail box used is Outlook.
If you are using Outlook, this code will do what you want:
http://www.datastrat.com/Code/MultipleEmail.txt
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
Private Sub Command5_Click()
Call Email
End Sub
Function Email(Optional varMsg As Variant, Optional varAttachment As Variant)
' ©Arvin Meyer 1999-2004
' Permission to use is granted if copyright notice is left intact.
' Permisssion is denied for use with unsolicited commercial email
Dim strTo As String, strSubject As String
'Set reference to Outlook
On Error GoTo Errhandler
Dim strBCC As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim objOutl As Outlook.Application
'Dim objEml As Outlook.MailItem
Dim i As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("qryToday", dbOpenSnapshot)
Set objOutl = CreateObject("Outlook.application")
'Set objEml = objOutl.createItem(olMailitem)
With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With
For i = 1 To rst.RecordCount
If Len(rst!EmailAddress) > 0 Then
strTo = rst!EmailAddress
Dim objEml As Outlook.MailItem
Set objEml = objOutl.CreateItem(olMailItem)
With objEml
.To = strTo
.Subject = strSubject
If Not IsNull(varMsg) Then
.Body = varMsg
End If
' Uncomment for attachment
' If Not IsMissing(varAttachment) Then
' .Attachments.Add varAttachment
' End If
.Send
End With
End If
Set objEml = Nothing
rst.MoveNext
Next i
ExitHere:
Set objOutl = Nothing
'Set objEml = Nothing
Set rst = Nothing
Set db = Nothing
Exit Function
Errhandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Function
"Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message
news:79F89E43-006A-428A...@microsoft.com...
> Hi
> Thanks for the code, but when i run the below code i got a error saying
> "3265: item not found in collection"
>
>
>
> Private Sub Command5_Click()
> Call Email
> End Sub
>
> Function Email(Optional varMsg As Variant, Optional varAttachment As
> Variant)
> ' ŠArvin Meyer 1999-2004
Yes i have changed my references to 'Microsoft Outlook 11.0 Object Library
and just copied and saved your funtion and created a command button which
calls the function as shown below
Private Sub Command3_Click()
Call Email
End Sub
Now when i try to run iam geting error called as "Argument not optional"
Please advise me.........
"Arvin Meyer [MVP]" wrote:
> Did you set a reference to your version of Outlook?
> --
> Arvin Meyer, MCP, MVP
> http://www.datastrat.com
> http://www.mvps.org/access
> http://www.accessmvp.com
>
>
> "Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message
> news:79F89E43-006A-428A...@microsoft.com...
> > Hi
> > Thanks for the code, but when i run the below code i got a error saying
> > "3265: item not found in collection"
> >
> >
> >
> > Private Sub Command5_Click()
> > Call Email
> > End Sub
> >
> > Function Email(Optional varMsg As Variant, Optional varAttachment As
> > Variant)
> > ' ©Arvin Meyer 1999-2004
"Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message
news:41DD0D59-D7F9-4EF3...@microsoft.com...
>> > ' ŠArvin Meyer 1999-2004
"Jason" <Ja...@hotmail.com> wrote in message
news:OBL6exPK...@TK2MSFTNGP03.phx.gbl...