X


[ Pobierz całość w formacie PDF ]
.3.Choose File �' Save As.The Save As dialog box appears, as shown inFigure 30-22.Figure 30-22: The Save As VisualBasic Module dialog box4.Choose Save as Module and click OK.The Convert Macro dialog box appears,as shown in Figure 30-23. 3596-X ch30.F 5/30/01 11:46 AM Page 987Chapter 30 &' Working with Visual Basic in Access 2002987Figure 30-23: The Convert Macrodialog box5.Select the options that include error handling and comments and clickConvert.Access briefly displays each new procedure as it is converted.When the con-version process finishes, the Conversion Finished message box appears.6.Click OK to remove the message box.7.Access displays the Modules object window of the Database window, asshown in Figure 30-24.Access names the new module Converted Macro - PrintReports.Figure 30-24: The newly converted moduleWhen you open the Module window for the new module, you can view the proce-dures created from the macros.Figure 30-24 shows the four functions that Accesscreated from the Print Reports macro: Print_Reports_Close, Print_Reports_Print,Print_Reports_Print_Preview, and Print_Reports_Show_List.Figures 30-25 and 30-26show samples of the new procedures. 3596-X ch30.F 5/30/01 11:46 AM Page 988Part V &' Access Application Tools988Figure 30-25: The Print_Reports_Close functionFigure 30-26: The Print_Reports_Print function 3596-X ch30.F 5/30/01 11:46 AM Page 989Chapter 30 &' Working with Visual Basic in Access 2002989At the top of each function, Access inserts four comment lines for the name of thefunction.The Function statement follows the comment lines.Access names thefunctions, using the macro library s name as a prefix (Print_Reports); the macroname (if one is supplied) for the suffix; and Close for the Close function.When you specify that you want Access to include error processing for the conver-sion, Access automatically inserts the OnError statement as the first command inthe procedure.The OnError statement tells Access to branch to other statementsthat display an appropriate message and then exit the function.Cross- Error processing is covered in more detail in Chapter 31.ReferenceThe statement beginning with DoCmd is the actual code that Access created fromthe macro.The DoCmd methods run Access actions from Visual Basic.An actionperforms important tasks, such as closing windows, opening forms, and setting thevalue of controls.In the Close macro, for example, Close Print Reports Dialog closesthe Print Reports dialog box.Access converts the Close macro action arguments tothe properly formatted parameters for the DoCmd methods.In the Print_Reports_Print function, the group of statements beginning with the Withcommand retrieves the settings of some of the controls in the Print Reports dialogbox.The DoCmd action prints various reports based on the value of the settings inthe dialog box.Chapter 31 covers conditional structures, such as the If.End Ifstatements you see in these functions.TipYou also can convert macros that are used in a form by choosing Tools �' Macro �'Convert Form s Macros to Visual Basic in Forms Design view.Using the Command Button Wizard to create VisualBasic codeA good way to learn how to write event procedures is to use the Command ButtonWizard.When Access creates a command button with a Wizard, it creates an eventprocedure and attaches it to the button.You can open the event procedure to seehow it works and then modify it to fit your needs.Cross- For more information about the Command Button Wizard, see Chapter 32.ReferenceThe Wizard speeds the process of creating a command button because it does allthe basic work for you.When you use the Wizard, Access prompts you for informa-tion and creates a command button based on your answers.You can create more than 30 types of command buttons by using the CommandButton Wizard.You can create a command button that finds a record, prints arecord, or applies a form filter, for example.You can run this Wizard by creatinga new command button on a form.Figure 30-27 shows a command button beingcreated in the Record Operations category, with the Delete Record action. 3596-X ch30.F 5/30/01 11:46 AM Page 990Part V &' Access Application Tools990Figure 30-27: The Command Button WizardNoteIn the Mountain Animal Hospital database is a form named Button Wizard VisualBasic Samples.This form, shown in Figure 30-28 in Design mode, contains theresult of running the Button Wizard with several selections.The Button WizardVisual Basic Samples form contains a dozen command buttons created with theCommand Button Wizard.You can review the procedures for each command but-ton on the form to see how powerful Visual Basic code can be.Figure 30-28: Examples of Command Button Wizard buttons 3596-X ch30.F 5/30/01 11:46 AM Page 991Chapter 30 &' Working with Visual Basic in Access 2002991To view the sample code, follow these steps:1.Display the Button Wizard Visual Basic Samples form in Design view.2.Display the Property window for the desired button.3.Click the Builder button (.) for the On Click event property to display thecommand button s Module window, with the procedure.Figure 30-28 shows the property sheet for the Delete Record command button andFigure 30-29 shows the code for the Delete Record command button.Figure 30-29: The Delete button s On Click procedureFigure 30-30 shows the code for a Dialer command button.The Phone_Dialer_Clickprocedure retrieves the text in the current field and then passes the text to a utilitythat dials the telephone. 3596-X ch30.F 5/30/01 11:46 AM Page 992Part V &' Access Application Tools992Figure 30-30: The Phone Dialer command button s OnClick procedure&' &' &' 3596-X ch31.F 5/30/01 11:46 AM Page 993C H A P T E R3131Using VisualBasic in Forms&' &' &' &'In This Chapterand ReportsUnderstandingmodulesUsing variables andhe Visual Basic language offers a full array of powerfuldata typesTcommands for manipulating records in a table, controlson a form, or just about anything else.This chapter continuesWorking with VisualChapter 30 s discussion of working with procedures in forms,Basic logicalreports, and standard modules.constructsHandling errorsUnderstanding ModulesFiltering dataprogrammaticallyChapter 30 allows you to create a few sample procedures andyou become somewhat familiar with the Visual Basic program-Programming list andming environment.But you may still be a little uncomfortablecombo boxeswith modules and procedures, as well as unsure when andhow to create them.Updating tablesModules and their procedures are the principal objects of theUsing ADO andVisual Basic programming environment.The programmingDAOcode that you write is placed in procedures that are containedin a module.The procedures can be independent procedures,&' &' &' &'unrelated to a specific form or report, or they can be integralparts of specific forms and reports [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • funlifepok.htw.pl
  •  

    Drogi uĹźytkowniku!

    W trosce o komfort korzystania z naszego serwisu chcemy dostarczać Ci coraz lepsze usługi. By móc to robić prosimy, abyś wyraził zgodę na dopasowanie treści marketingowych do Twoich zachowań w serwisie. Zgoda ta pozwoli nam częściowo finansować rozwój świadczonych usług.

    Pamiętaj, że dbamy o Twoją prywatność. Nie zwiększamy zakresu naszych uprawnień bez Twojej zgody. Zadbamy również o bezpieczeństwo Twoich danych. Wyrażoną zgodę możesz cofnąć w każdej chwili.

     Tak, zgadzam się na nadanie mi "cookie" i korzystanie z danych przez Administratora Serwisu i jego partnerĂłw w celu dopasowania treści do moich potrzeb. Przeczytałem(am) Politykę prywatności. Rozumiem ją i akceptuję.

     Tak, zgadzam się na przetwarzanie moich danych osobowych przez Administratora Serwisu i jego partnerĂłw w celu personalizowania wyświetlanych mi reklam i dostosowania do mnie prezentowanych treści marketingowych. Przeczytałem(am) Politykę prywatności. Rozumiem ją i akceptuję.

    Wyrażenie powyższych zgód jest dobrowolne i możesz je w dowolnym momencie wycofać poprzez opcję: "Twoje zgody", dostępnej w prawym, dolnym rogu strony lub poprzez usunięcie "cookies" w swojej przeglądarce dla powyżej strony, z tym, że wycofanie zgody nie będzie miało wpływu na zgodność z prawem przetwarzania na podstawie zgody, przed jej wycofaniem.