Code to create Access file and tables:
Code:
Public Sub ConstructionExtract()
'exports data to ConstructionExtract Access file
'copies file to zip folder
'opens Outlook object and attaches file to msg and sends
Dim strZip As String
Dim strExtract As String
Dim Catalog As Object
strZip = gstrBasePath & "Program\Editing\ConstructionExtract.zip"
strExtract = gstrBasePath & "Program\Editing\ConstructionExtract.accdb"
'create new database
Set Catalog = CreateObject("ADOX.Catalog")
Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strExtract & ";"
Set Catalog = Nothing
'import tables to the ConstructionExtract Access file
CurrentDb.Execute "SELECT * INTO Bituminous IN '" & strExtract & "' FROM ConstructionBIT;"
CurrentDb.Execute "SELECT * INTO BituminousMD IN '" & strExtract & "' FROM ConstructionBMD;"
CurrentDb.Execute "SELECT * INTO Concrete IN '" & strExtract & "' FROM ConstructionCONC"
CurrentDb.Execute "SELECT * INTO Emulsion IN '" & strExtract & "' FROM ConstructionEMUL;"
CurrentDb.Execute "SELECT * INTO PGAsphalt IN '" & strExtract & "' FROM ConstructionPG;"
CurrentDb.Execute "SELECT * INTO SoilsAgg IN '" & strExtract & "' FROM ConstructionSA;"
CurrentDb.Execute "SELECT * INTO SampleInfo IN '" & strExtract & "' FROM ConstructionSampleInfo;"
'create empty zip folder
'found this on web, no idea what the Print line does but if it isn't there, this won't work
Open strZip For Output As #1
Print #1, "PK" & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'copy file into zip folder
Dim objApp As Object
Set objApp = CreateObject("Shell.Application")
'variable for source file doesn't seem to work in this line
'also double parens not in original code but won't work without
objApp.NameSpace((strZip)).CopyHere gstrBasePath & "Program\Editing\ConstructionExtract.accdb"
'open Outlook, attach zip folder, send e-mail
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = "email address here"
''.cc = ""
''.bcc = ""
.Subject = "Laboratory Data"
.HTMLBody = "Construction data extract: " & Now
.Attachments.add (strZip)
.DeleteAfterSubmit = True 'to not save in sent bin
''.Display
.Send
End With
'delete zip folder and ConstructionExtract.accdb
Kill strZip
Kill strExtract
CurrentDb.Execute "UPDATE Updates SET ConstructionExtract=#" & Date & "#"
End Sub