IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Access
Search Access Group:

Advanced
-Collapse +Expand Access To/From
To/FromCODEGuides
-Collapse +Expand Access Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Access & VBAAccess VBALanguage Det...   Print This     
  From the January 2016 Issue of Prestwood eMag
 
Access Language Details:
Access VBA Custom Routines (Sub, Function)
 
Posted 16 years ago on 11/11/2008 and updated 1/29/2009
Access Code Snippet:
 A flashcard from our Access Flashcards Library
 A code snippet from our Access Code Snippets Page

KB101596

Languages Focus: Custom Routines

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

Access VBA Custom Routines

Access VBA is a non-OOP language with some OOP features. It offers both Subs and Functions. A Sub does not return a value while a Function does. When Subs and Functions are used in a class module, they become the methods of the class.

Syntax Example:
Sub SayHello(ByVal pName As String)
  MsgBox ("Hello " & pName)
End Sub
 
Function Add(pN1 As Integer, pN2 As Integer) As Integer
  Add = pN1 + pN2
End Function

Access VBA Sub & function Example

If you define the following sub and funtion:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subs and Functions
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoSomeCode(ByRef pMessage)
    MsgBox (pMessage)
End Sub
Function GetLastDOW(ADate, AWeekDayConst)
    While Weekday(ADate) <> AWeekDayConst
        ADate = DateAdd("d", -1, ADate)
    Wend
   
    GetLastDOW = ADate
End Function

You can call them. For example, the following code is from the click event of a button:

Private Sub Toggle6_Click()
    DoSomeCode ("Hello3")
    MsgBox "Last Monday was " & GetLastDOW(Date, vbMonday)
End Sub

More Info


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P177A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101596 Counter
17885
Since 11/11/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]