totalnovice2
Registered User.
- Local time
- Today, 22:07
- Joined
- May 21, 2013
- Messages
- 36
Hi.
Please can you advise what is wrong with this code?
It works as far as the data from access is taken over to excel and then the save box will come up - the issue is that I want to to automatically save this as a file name, open up outlook, attach it to an e-mail and send it.
Please let me know if you are able to assist.
Many thanks.
Please can you advise what is wrong with this code?
It works as far as the data from access is taken over to excel and then the save box will come up - the issue is that I want to to automatically save this as a file name, open up outlook, attach it to an e-mail and send it.
Please let me know if you are able to assist.
Many thanks.
Code:
Private Sub Command154_Click()
On Error Resume Next
Dim appExcel As Excel.Application
Dim wbook As Excel.Workbook
Dim wsheet As Excel.Worksheet
Set appExcel = New Excel.Application
Set wbook = appExcel.Workbooks.Open("C:\Users\me\desktop\Auto\Access\New Access\Latest\Tmobile & Orange.xltm")
Set wsheet = wbook.Worksheets("Permit Request Form")
With wsheet
.Range("F2").Value = Forms![Front Page]![Address #2]
.Cells(3, 2).Value = Forms![Front Page]![Site 2 Owner]
.Cells(3, 3).Value = Forms![Front Page]![Site 2 Name]
.Cells(3, 4).Value = Forms![Front Page]![Postcode S2]
.Cells(3, 5).Value = Forms![Front Page]![Text98]
.Cells(3, 6).Value = Forms![Front Page]![Text139]
.Cells(3, 25).Value = Forms![Front Page]![Combo79] & " " & Forms![Front Page]![Combo81]
wbook.ActiveDocument.SaveAs2 FileName:="C:\Users\Public\" & Forms![Front Page]![txt1141] & " " & Forms![Front Page]![Combo79] & " " & "Orange Tmob" & ".xltm"
Call Mail_Radio_Outlook4("C:\Users\Public\" & Forms![Front Page]![txt1141] & " " & Forms![Front Page]![Combo79] & " " & "Orange Tmob" & ".xltm")
End With
End Sub
Function Mail_Radio_Outlook4(activedoc As String)
'Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim acc_req As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hello.<br> <br> Please Find attached request for access. <br>"
acc_req = "Orange / Tmob Access request" & " " & [Forms]![Front Page]![Text98].Value & " " & Forms![Front Page]![Site 2 Name].Value
With OutMail
On Error Resume Next
.Display
.To = [EMAIL="example@Example.com"]example@Example.com[/EMAIL]
.CC = ""
.Subject = acc_req
.Attachments.Add (wbook)
.HTMLBody = strbody & "<br>" & .HTMLBody
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
MsgBox "Your E-mail has been generated. Please add your climbing certificates", vbInformation + vbOKOnly, "E-mail Sent"
wbook.Close True
Set wbook = Nothing
Set appExcel = Nothing
End Function