Is there any way to export object query with current date (1 Viewer)

adnanhome

Registered User.
Local time
Yesterday, 23:28
Joined
Nov 12, 2008
Messages
16
I have situation if you could solve this also. I have following code it works fine. Only thing I want to add date to my object.


DoCmd.SendObject acSendQuery, "VdrDeliveredtoDock" & Format(Date, "MMM-DD-YYYY") & ".xlsx", acFormatXLSX, "abc@gmail.com, xyz@yahoo.com, "Dry Vendor delivered to DOCK", "Good Morning," & vbNewLine & "Attached please find the subject report." & vbNewLine & "Thanks,"

It attach my query as excel file in my outlook but want to add date to my object. Is it possible ?
 

Ranman256

Well-known member
Local time
Today, 02:28
Joined
Apr 9, 2015
Messages
4,337
export the reg. query to a file with the date:

vFile = "c:\folder\VdrDeliveredtoDock" & Format(Date, "MMM-DD-YYYY") & ".xlsx"
docmd.TransferSpreadsheet acExport ,acSpreadsheetTypeExcel12,"VdrDeliveredtoDock",vFile,true

then email it (NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE):

vTo = "abc@gmail.com"
vSubj = "Dry Vendor delivered to DOCK",
vBody = "Good Morning," & vbNewLine & "Attached please find the subject report." & vbNewLine & "Thanks,"

Email1 vTo, vSubj, vBody, vFile


Code:
Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem

On Error GoTo ErrMail

'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.createitem(olmailitem)

With oMail
    .To = pvTo
    .Subject = pvSubj
    If Not IsNull(pvBody) Then .Body = pvBody
    If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1
    
    .Display True
    '.Send
End With

Email1 = True
endit:
Set oMail = Nothing
Set oApp = Nothing
Exit Function

ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume endit
End Function
 
Last edited:

adnanhome

Registered User.
Local time
Yesterday, 23:28
Joined
Nov 12, 2008
Messages
16
export the reg. query to a file with the date:

vFile = "c:\folder\VdrDeliveredtoDock" & Format(Date, "MMM-DD-YYYY") & ".xlsx"
docmd.TransferSpreadsheet acExport ,acSpreadsheetTypeExcel12,"VdrDeliveredtoDock",vFile,true

then email it (NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE):

vTo = "abc@gmail.com"
vSubj = "Dry Vendor delivered to DOCK",
vBody = "Good Morning," & vbNewLine & "Attached please find the subject report." & vbNewLine & "Thanks,"

Email1 vTo, vSubj, vBody, vFile


Code:
Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem

On Error GoTo ErrMail

'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.createitem(olmailitem)

With oMail
    .To = pvTo
    .Subject = pvSubj
    If Not IsNull(pvBody) Then .Body = pvBody
    If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1
    
    .Display True
    '.Send
End With

Email1 = True
endit:
Set oMail = Nothing
Set oApp = Nothing
Exit Function

ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume endit
End Function

Thanks a lot Ranman I will try and let you know.
 

Users who are viewing this thread

Top Bottom