Results 1 to 2 of 2

Turning Private Function Into Public

  1. #1
    g4tv4life is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    50

    Turning Private Function Into Public

    Hello fellow access warriors,



    I'm trying to take a private function and turn it public to reduce bloat,

    Code:
    Private Sub Text0_AfterUpdate()
    Select Case [Text0]
    Case "N"
    Text0 = "No"
    Case "Y"
    Text0 = "Yes"
    End Sub
    Here's my code, I've tried converting it to public as shown here

    Code:
    Public Function Formatter()
    Select Case Me
    Case "N"
    Me = "No"
    Case "Y"
    Me = "Yes"
    End Sub
    Then for the box I use

    Code:
    Private Sub Text0_AfterUpdate()
    Formatter
    End Sub
    I'm guessing theres something glaringly obvious I'm missing here as its giving me a type mismatch error.

    What am I missing? thanks guys

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,254
    Me is a special word in VBA. It is an alias for form or report object name.

    A function is used to return a value to a calling procedure.

    Sub Text0_AfterUpdate()
    Me.Text0 = Formatter(Me.Text0)
    End Sub

    Function Formatter(varData)
    Select Case varData
    Case "N"
    Formatter = "No"
    Case "Y"
    Formatter = "Yes"
    End Select
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-17-2013, 06:10 AM
  2. Calling a Private Function from Another Form
    By MintChipMadness in forum Programming
    Replies: 1
    Last Post: 01-07-2013, 12:08 PM
  3. Making a Public Function more flexible
    By sjs94704 in forum Programming
    Replies: 2
    Last Post: 12-10-2012, 02:21 PM
  4. Calling fields into VBA Private Sub
    By fullshape in forum Programming
    Replies: 3
    Last Post: 02-18-2011, 09:22 AM
  5. Replies: 9
    Last Post: 12-20-2010, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums