Visual Basic.NET
  Home arrow Visual Basic.NET arrow Programming Fundamentals Using VBA
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Programming Fundamentals Using VBA
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 26
    2005-07-28

    Table of Contents:
  • Programming Fundamentals Using VBA
  • Creating Procedures
  • Declaring Variables
  • Constants
  • Control Structures
  • The ElseIf Structure
  • Do Loop
  • Arrays
  • Dynamic Arrays

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programming Fundamentals Using VBA


    (Page 1 of 9 )

    This article will provide you with a chance to study the fundamentals of programming, with specific reference to the syntax of the VBA language. Variables and arrays will be discussed in detail. This article is excerpted from chapter six of the book Access VBA Programming, written by Charles E. Brown and Ron Petusha (McGraw-Hill/Osborne, 2004; ISBN: 0072231971).

    In Chapter 5 you learned about the VBA environment by looking at its structure, concepts, and editor. In this chapter, we are going to study the fundamentals of all programming while, at the same time, examine the specific syntax of the VBA language. We are going to review concepts from Chapter 5 and study them in greater detail, beginning with a review of the places where the code is stored and the types of blocks it is stored in. While discussing that, we will visit the subject of variables in greater detail. It is difficult to talk about variables without discussing a special type of variable called an array.

    We are also going to look at some of the built-in tools that VBA gives you to make your job easier. We will conclude our discussion by looking at the various types of programming structures and how they are used in a VBA environment.

    Programming Fundamentals

    As stated in Chapter 5, VBA code is written and stored within modules. Recall that there are two basic types of modules: those associated with forms or reports, and a general module for holding procedures that is applicable to the whole project.

    There is one other type, called a class module, which contains code associated with an object. We have discussed modules already in the previous chapters and will be referring to them throughout the rest of the book.

    Before you can write VBA code, you need to be able to create the module. Since form or report modules are created through their respective forms and reports, we will focus on creating standard modules here.

    Creating Standard Modules

    There are a couple of different ways of creating a standard module. The easiest way is to use the Modules category of objects right in the Database window, as shown in Figure 6-1. All you need to do is click on New and you are taken to the VBA Editor with a module created, as shown in Figure 6-2.

    VBA assigned your new module a temporary name of Module1. You will probably want to give it a more descriptive name. This can be done from the Properties window of the VBA Editor or directly in the Database window.

    As an example, in the VBA Editor, highlight the name Module1 in the Properties window, as shown in Figure 6-3, and rename it. You can call it myFirstModule. Once you have changed it in the Properties window, the name is changed in the Project window as well as in the Database window in Access (under the Modules category).


    Figure 6-1.  The Modules category selected in the Database window  

     
    Figure 6-2.  The VBA Editor with a module open

    In addition, you should click on the Save icon in the toolbar. You will be prompted to confirm the name, as shown here:

     

    Now you can confirm that the name has been changed in the Project window (Figure 6-4) and the Database window Figure 6-5).

     
    Figure 6-3.  The Name property


    Figure 6-4.  Project window after renaming the module 


    Figure 6-5.  Database window after renaming the module

    NOTE


    You can also change the name in the Database window by right-clicking it and selecting the Rename menu command.

    More Visual Basic.NET Articles
    More By McGraw-Hill/Osborne


       · how to create visual basic programmig using if else and for loop
     

    Buy this book now. This article is excerpted from chapter six of the book Access VBA Programming, written by Charles E. Brown and Ron Petusha (McGraw-Hill/Osborne, 2004; ISBN: 0072231971). Check it out at your favorite bookstore today. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek