Email a query (1 Viewer)

ECEK

Registered User.
Local time
Today, 04:23
Joined
Dec 19, 2012
Messages
717
I have a command button that opens Outlook (and contains my signature...wohooo!!!).

Private Sub Command2_Click()
Dim objOutlook As Object
Dim objItem As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(olMailItem)
With objItem
.Subject = Title
End With
objItem.Display
End Sub


I want to attach a Query called "New Process" to the email along with a subject and body text.

Would sombody be so kind as to illustrate how best to do this in Access 2010.

Much obliged
 

myezul

New member
Local time
Today, 06:23
Joined
Jan 8, 2015
Messages
4
U can use something similar

Code:
Private Sub Command0_Click()
Dim objOutlook As Object
Dim objItem As Object
[COLOR=Blue]Dim Mydb As Database
Dim Rst As Recordset
Dim body[/COLOR]

[COLOR=Blue]Set Mydb = CurrentDb
Set Rst = Mydb.OpenRecordset("select", dbOpenForwardOnly)
With Rst
Do While Not .EOF
body = body & ![CodCl] & " | " & ![produs] & " | " & ![grupa] & vbCrLf
.MoveNext
Loop
End With[/COLOR]


Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(olMailItem)

With objItem
.Subject = Title
[COLOR=Blue].body = "testing" & vbCrLf & " " & body[/COLOR]
End With
objItem.Display
Rst.Close
Set Rst = Nothing
End Sub
I would export the query result, and attach it to an email, i consider it a faster way of sending data, because if the query has a lot of records it would take access some time to write all of the data.
 
Last edited:

ECEK

Registered User.
Local time
Today, 04:23
Joined
Dec 19, 2012
Messages
717
Compile error:
Expected user-defined type, not project

Mydb As Database

Does anybody have any code to export a query, email it (with a signature) then delete the file?
 

ECEK

Registered User.
Local time
Today, 04:23
Joined
Dec 19, 2012
Messages
717
I can use a macro to do what I want to do using EMailDatabaseObject. It just doesnt add my signature.
 

pr2-eugin

Super Moderator
Local time
Today, 04:23
Joined
Nov 30, 2011
Messages
8,494
The use of Database is an ambiguity. Use Mydb As DAO.Recordset
 

Users who are viewing this thread

Top Bottom