A Tutorial for Access 2007 VBA

A Tutorial for Access 2007 VBA thumbnail
Without VBA, you would need to use a calculator to get age.

Microsoft Access 2007 is a desktop database application. Microsoft includes Visual Basic for Applications (VBA) as a way for you to extend the functionality of Access 2007 using Visual Basic. For example, Access does not provide a built-in function to calculate age, but with VBA you could create a function to do this. In the Visual Basic Editor, you can create modules and classes. A module is a container for VBA code containing declarations and procedures. There are two types of modules. A standard module is not associated with a particular object while a class module is.

Instructions

    • 1

      Click "Start," "All Programs," "Microsoft Office" and "Microsoft Access 2007."

    • 2

      Open an existing database using "File," "Open."

    • 3

      Click "Visual Basic" on the "Database Tools" tab of the ribbon.

    • 4

      Click "Module" from the "Insert" menu. Select "Procedure" from the "Insert" menu. Enter a name for the procedure. Select a type, such as "Function," and a scope and then click "OK."

    • 5

      Enter the code for your procedure. For example:

      Public Function Age(varBirthDate As Variant) As Integer

      Dim varAge As Variant

      If IsNull(varBirthDate) Then Age = 0: Exit Function

      varAge = DateDiff("yyyy", varBirthDate, Now)

      If Date < DateSerial(Year(Now), Month(varBirthDate), Day(varBirthDate)) Then

      varAge = varAge - 1

      End If

      Age = CInt(varAge)

      End Function

    • 6

      Click "Immediate Window" from "View." Type "? Age("1/2/1956")" and press "Enter" to test your code. You should get "54" if the current date is in 2010.

    • 7

      Click the floppy disk icon on the toolbar to save your work.

Related Searches:

References

Resources

  • Photo Credit calculating image by timur1970 from Fotolia.com

Comments

You May Also Like

  • MS Access 2007 VBA Tutorial

    Further customize your MS Access 2007 databases using Visual Basic for Applications, or VBA. Use VBA to create macros, add events to...

  • Online Tutorial for MS Access 2007

    Microsoft Office Access is consumer-friendly database software that does not require the user to have expertise of any programming languages. Through the...

  • How to Learn VBA for Access

    Visual Basic for Applications (VBA) is the programming language Microsoft Office developers use to create custom reports, queries, data entry forms and...

  • Advanced Access 2007 Training

    Beginning Microsoft Access 2007 training helps computer users understand what a database is and how Access works. Advanced training goes beyond using...

  • How to Calculate Time in Microsoft Access 2007

    The Microsoft Access 2007 database application allows you to create a function to calculate elapsed time, which can be vital for timesheet...

  • Microsoft Access VBA Tutorial

    VBA (Visual Basic for Applications) is part of Microsoft Access, but it uses a different model than VBA in other Microsoft application...

  • How to Access VBA Programming for Absolute Beginners

    Microsoft Access is a database program included in the Microsoft Office suite of applications. With Microsoft Access, create a database to suit...

  • Excel VBA 2007 Tutorial

    Microsoft Visual Basic for Applications (VBA) is a subset of Visual Basic specifically designed for you to be able to customize Microsoft...

  • MS Access Modules Tutorial

    Microsoft Access is a personal database management system (DBMS). While the database features are not as robust as an enterprise level DBMS,...

Related Ads

Featured