Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Using an Object Model - Pg. 189

Using Visual Basic to Automate Your Database 189 Figure 5-7. The e-mail message sent by clicking the Transfer Data button on the Demonstrations form Here's code that we'll build on in later chapters as we continue to develop the HelloWorld database application. You could use code similar to this to create a task or a calendar entry in Outlook as well. Private Sub cmdTransferData_Click() On Error GoTo Err_TransferData_Click Dim Dim Dim Dim db As Database tbl As TableDef tblName As String intAnswer As Integer Set db = CurrentDb Set tbl = db.TableDefs("CampaignExpenses") tblName = tbl.Name intAnswer = MsgBox(tblName & " were last updated on" & " " & _ tbl.LastUpdated, vbYesNo + vbQuestion, _ "Do You Want To Export Expenses?") If intAnswer = vbYes Then DoCmd.SetWarnings False DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _ tblName, FilePath & "ch05\campaignexpenses.xls", True DoCmd.SetWarnings True Call MailMessage Else MsgBox "Data Won't Be Exported" End If Exit_TransferData_Click: Exit Sub Err_TransferData_Click: MsgBox "An Error Occurred." Resume Exit_TransferData_Click End Sub