Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Creating an Event Procedure - Pg. 144

Using Visual Basic to Automate Your Database 144 7. 8. The lines of code you entered in the last two steps are an example of a programming structure you can use to control the conditions and flow of database operations. The If...Then...Else statement defines the conditions that determine which set of actions occur in the procedure. Here, if a user clicks the Yes button in the message box (which will return the value vbYes ), the DoCmd methods run and the spreadsheet data is imported. If the user doesn't click the Yes button ( Else ), a message box confirms that no data will be imported. Click the Save button on the Visual Basic Editor toolbar, and then press Alt+F11 to see the Import form in Design view. Click View, Form View (or click the View button on the toolbar), and then click the Import Expenses button. The message box we defined is displayed, as shown here: 9. Click Yes in the message box, switch to the Database window, and then open the Cam- paignExpenses table in Datasheet view. You'll see the data from the spreadsheet, as shown here: