BadgerLikeSpeed
Registered User.
- Local time
- Today, 23:46
- Joined
- Feb 7, 2013
- Messages
- 35
Hi,
I'm pretty new to Access, and teaching myself as I'm going along, so any help will have to be explained in simple terms. Sorry.
To the point...
I'm trying to get access to export my tables to a new database, attach that to an email, send it and then delete the file once it's been sent. (There is a good reason for this)
Initially I had Access export the tables to an excel sheet and email it. Everything worked fine! Then I decided to change it to an Access database, and my problems began.
This is my code:
When I run this I get a run-time error '-2147024864 (80070020)' at
.attachments.Add (LFilename)
Help gives me this information:
Automation error (Error 440)
This page is specific to the Visual Basic for Applications (VBA) Language Reference for Office 2010. When you access Automation Objects, specific types of errors can occur. This error has the following cause and solution:
I presume that Access is still trying to access/edit the newly created database when it is also trying to attach it to the email. How do I force it to leave it alone? (Sorry for the terribly technical language!)
Any help would be greatly appreciated...
I'm pretty new to Access, and teaching myself as I'm going along, so any help will have to be explained in simple terms. Sorry.
To the point...
I'm trying to get access to export my tables to a new database, attach that to an email, send it and then delete the file once it's been sent. (There is a good reason for this)
Initially I had Access export the tables to an excel sheet and email it. Everything worked fine! Then I decided to change it to an Access database, and my problems began.
This is my code:
Code:
Private Sub OpenFormExport_Click()
Dim ws As Workspace
Dim db As Database
Dim LFilename As String
Set ws = DBEngine.Workspaces(0)
'Create new database in current folder
LFilename = CurrentProject.Path & "\ExportWatwick.mdb"
Set db = ws.CreateDatabase(LFilename, dbLangGeneral)
'Export tables to new database
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatCrew", "WatCrew"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatElect", "WatElect"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatEngDataMonth", "WatEngDataMonth"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatEngDataWeek", "WatEngDataWeek"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatJobList", "WatJobList"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatMiscTab", "WatMiscTab"
DoCmd.TransferDatabase acExport, "Microsoft Access", LFilename, acTable, "WatOOP", "WatOOP"
'Export via Email
Dim olLook As Object 'Start MS Outlook
Dim olNewEmail As Object 'New email in Outlook
Dim strContactEmail As String 'Contact email address
'Open Outlook
Set olLook = CreateObject("Outlook.Application")
Set olNewEmail = olLook.createitem(0)
strEmailSubject = "Watwick Data Report"
strEmailText = ""
strContactEmail = "EMAIL ADDRESS"
'strCc = "EMAIL ADDRESS"
With olNewEmail 'Attach template
.To = strContactEmail
'.CC = strCc
.body = strEmailText
.subject = strEmailSubject
.attachments.Add (LFilename)
.display
'.send
End With
'Delete File
Kill (LFilename)
End Sub
When I run this I get a run-time error '-2147024864 (80070020)' at
.attachments.Add (LFilename)
Help gives me this information:
Automation error (Error 440)
This page is specific to the Visual Basic for Applications (VBA) Language Reference for Office 2010. When you access Automation Objects, specific types of errors can occur. This error has the following cause and solution:
- An error occurred while executing a method or getting or setting a property of an object variable The error was reported by the application that created the object.
Check the properties of the Err object to determine the source and nature of the error. Also try using the On Error Resume Next statement immediately before the accessing statement, and then check for errors immediately following the accessing statement.
I presume that Access is still trying to access/edit the newly created database when it is also trying to attach it to the email. How do I force it to leave it alone? (Sorry for the terribly technical language!)
Any help would be greatly appreciated...