Results 1 to 5 of 5
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    Post public function values from form

    I have an AfterUpdate in a form:



    Private Sub transactionTypeID_AfterUpdate()
    Dim TransType As String
    TransType = TransactionType.Value


    Select Case TransType
    Case "Set up"
    ....and so on....

    All is great with this, but when I changed the afterUpdate to a function to this:
    **************
    Private Sub transactionTypeID_AfterUpdate()
    Call myViews
    end sub
    **************
    Public Function myViews()


    Dim TransType As String
    TransType = Forms![Frm Cash Register]!me.TransactionType.Value
    MsgBox "The variable is " + TransType

    end function
    *********************************



    I can't get the code on the public function to execute. I does not give me an error, it just doesn't do anything.
    How do I get the value from the form to be used in the public function?
    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    functons return a value. you did not assign the final value in the function...

    msgbox "The variable is " + myviews()

    Code:
    Public Function myViews()
    myViews=   Forms![Frm Cash Register]!me.TransactionType.Value
    end function

  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    sorry, but I am not getting this.
    I copied in your code but Access is still bypassing everything.
    I am trying to read about returning a value and it is very confusing.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Here's how a function works. Lets say you want a function to add two numbers together and return the result.
    Code:
    Function fcnAddTwo(a as long, b as long) as long
        fcnAddTwo = a + b
    End Function
    This says that the two numbers to be added are both long and the result returned will be long.
    Notice that the function sets the value to be returned to its own name.

    Now to use the function you could use:

    Code:
    sub cmdButton_Click()
        dim num1 as long
        dim num2 as long
        dim rslt as long
        num1 = 5
        num2 = 10
        rslt = fcnAddTwo(num1, num2)
        debug.print rslt
    End Sub
    Notice that rslt is set to the value of the function - it gets the value returned.

    Hope this helps.
    Last edited by davegri; 10-02-2017 at 07:41 AM. Reason: syntax

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Public Function myViews()
         Dim TransType As String
        
         TransType = Forms![Frm Cash Register]!me.TransactionType  '<<<---- ????
         MsgBox "The variable is " & TransType       ' << use ampersand to concatenate
    End Function
    Hmmmm, very strange. I've never seen this syntax before... Where is the function located? In a standard module or behind the form?



    Also, would suggest not having spaces, punctuation or special characters (exception is the underscore) in object names.

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

Similar Threads

  1. Public Function
    By ShostyFan in forum Programming
    Replies: 3
    Last Post: 09-30-2017, 09:58 AM
  2. VBA Can't find Public Function
    By GraeagleBill in forum Programming
    Replies: 15
    Last Post: 03-17-2016, 09:38 PM
  3. Replies: 3
    Last Post: 06-24-2015, 06:25 PM
  4. Replies: 4
    Last Post: 11-13-2014, 08:00 PM
  5. Turning Private Function Into Public
    By g4tv4life in forum Programming
    Replies: 1
    Last Post: 02-04-2014, 05:31 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