Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

send mail

0 views
Skip to first unread message

Ranjit kurian

unread,
Sep 27, 2008, 2:36:01 PM9/27/08
to
i have query called as qryToday and its in data sheet view, i would like to
send mail to list of people(i have a table with list of mail id and names
'tblNameList' ) the qry Today to everybody who's email id are mentioned in
tblNameList table.

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.

Arvin Meyer [MVP]

unread,
Sep 27, 2008, 11:06:19 PM9/27/08
to
"Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message
news:066A9E7B-52C2-4655...@microsoft.com...

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


Ranjit kurian

unread,
Sep 28, 2008, 1:37:00 AM9/28/08
to
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
' 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

Arvin Meyer [MVP]

unread,
Sep 28, 2008, 9:36:20 AM9/28/08
to
Did you set a reference to your version of Outlook?

"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

unread,
Sep 29, 2008, 12:34:01 PM9/29/08
to
Hi

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

Arvin Meyer [MVP]

unread,
Sep 30, 2008, 8:50:16 AM9/30/08
to
The first 2 arguments were NOT optional and you changed the function. I
don't see anywhere where you've provided strSubject.


"Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message

news:41DD0D59-D7F9-4EF3...@microsoft.com...

>> > ' ŠArvin Meyer 1999-2004

Jason

unread,
Oct 8, 2008, 12:14:29 AM10/8/08
to
I've had to add & "" after email address to get around argument not optional
even though the field does have valid text.

"Ranjit kurian" <Ranjit...@discussions.microsoft.com> wrote in message
news:41DD0D59-D7F9-4EF3...@microsoft.com...
>> > ' ŠArvin Meyer 1999-2004

Jason

unread,
Oct 8, 2008, 12:16:23 AM10/8/08
to
I'm also getting compile error:
Invalid Use Of Property
for: .ReadReceiptRequested
"Jason" <Ja...@hotmail.com> wrote in message
news:OBL6exPK...@TK2MSFTNGP03.phx.gbl...

Jason

unread,
Oct 8, 2008, 12:20:34 AM10/8/08
to
Set objOutlook = CreateObject("Outlook.application") is generating error:
429: ActiveX component can't create object.

"Jason" <Ja...@hotmail.com> wrote in message
news:OBL6exPK...@TK2MSFTNGP03.phx.gbl...

0 new messages