Results 1 to 2 of 2
  1. #1
    g4tv4life is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014

    Turning Private Function Into Public

    Hello fellow access warriors,

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

    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

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

    Private Sub Text0_AfterUpdate()
    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 online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    The Great Land
    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: 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
Other Forums: Microsoft Office Forums - Senior Forums