Share this Page URL

Chapter 17. Using Visual Basic to Manage... > Using Visual Basic to Work with Data... - Pg. 597

Using Visual Basic to Manage Data 597 If you wanted to use the data in an Access database to add an item to the Tasks folder in Outlook, you could modify this code so that a procedure declared an object variable with the type TaskItem ( Dim myItem as TaskItem ) and then assigned an object reference to this vari- able with a line such as Set myItem = myOlApp.CreateItem(olTaskItem ). You would replace the constant olFolderContacts with the constant olFolderTasks in the line that calls the Get- DefaultFolder method. For a calendar item, you would use an object such as MeetingItem or AppointmentItem together with olFolderCalendar. Creating an Excel Spreadsheet from Access In several chapters of this book, we've used a Visual Basic procedure to transfer campaign expense data between Access and Excel. The procedures referred to Excel spreadsheets that had already been created and saved. If those files weren't available--if another user happened to be working with a file we needed when the procedure ran or if a file had been moved--the procedures would not have run successfully. In this section, instead of relying on an Excel file that already exists, we'll describe how you can use Visual Basic to create an Excel spreadsheet from Access. The procedure we'll create exports ex- pense records that require approval (expenses greater than $500) and then adds a column heading to the spreadsheet for the column in which approval can be noted. In the example, we'll use the Excel Workbook and Worksheet objects as well as several properties and methods associated with these objects. Create an Excel spreadsheet from Access 1. In the HelloWorld17 database, select the form named ExpenseApproval in the Database win- dow, and then click Design. You'll see the form shown here: