Monday, November 17, 2014

Visual Basic For Access Tutorial

Visual Basic is used to help create more advanced Microsoft Access databases. Visual Basic code can be added to objects to perform certain tasks during an event. Visual Basic is also referred to as VBA or Visual Basic for Applications since it's used as a programming tool within Microsoft Access. With Access's help feature, even beginners can begin using and learning Visual Basic for their databases.


Forms and Reports


Add Visual Basic code to forms and reports. Forms and reports contain objects. Right-click any object or any blank portion of a form or report and choose "Properties." Click the "Event" tab to access all potential events for a particular object. Events vary based on the object. Click the ellipsis next to any event text box and choose "Code Editor" to open the Visual Basic editor for that object.


The basic start and end code are placed for you automatically. Enter your desired Visual Basic code between the start and end. Only code between those two points will be recognized and used for your object. Save your changes by clicking the "Save" button on the toolbar. Exit the Visual Basic Editor and continue editing your form or report.


Visual Basic Editor


Open the Visual Basic Editor by going to "Tools," selecting "Macro" and choosing "Visual Basic Editor." On the left of the screen is the project window. Double-click any form or report to open the Visual Basic code window. Through this window, no preliminary code is provided. You must create all functions and methods for objects from scratch. If you want to create a note for your code, precede it with an apostrophe. Notes are used to explain portions of code for future reference and debugging.


Debug and Run


Debug your code before you run it. Debugging shows you any possible errors. Go to the "Debug" menu while in the Visual Basic editor. Choose "Debug" to check for errors. Error messages will appear at the bottom of the screen along with the line number. Note that the error isn't always on the particular line. The line is just where the error resulted. Check all code in the section where the error was found. Breakpoints can be used to run only certain lines of code to narrow down an error.


Run your Visual Basic code by going to the "Run" menu. You can run certain sections or sub-sections and macros. Code can also be run by saving code as a macro and running the macro or by running the event on an object that the code applies to.


Help


Use Microsoft Access Visual Basic help to learn the syntax and purpose of each portion of code. Access also provides you with suggestions as you type to assist you. Go to "Help" while in the Visual Basic Editor. Choose "Microsoft Access Visual Basic Help." Select "Microsoft Access Visual Basic Reference" to view details on various portions of Visual Basic programming.

Tags: Visual Basic, Basic code, Microsoft Access, Visual Basic code, Basic Editor, Access Visual, Access Visual Basic