Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Public Function? (2000)

    Afternoon All,

    How can I pass a value from a form to a Public Function where this value will stay in memory until the db is closed?

    Thanks.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Public Function? (2000)

    Declare a variable as public in a standard module (not a form or report module). In the example, I use a string variable, but you can adapt it to your needs.

    Public strMyVar As String

    You can assign a value to this variable while the form is open:

    strMyVar = Forms!frmMyForm!txtMyTextBox

    You can refer to the public variable in all code in all modules in this database.

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Public Function? (2000)

    Good Morning,
    Thanks for the suggestions, I went with this:

    Public Type UserInfo
    ViewID As Integer
    AccessID As Integer
    Active As Boolean
    Password As String
    UserID As String
    SecurityID As String
    End Type

    Public User As UserInfo

    Works great.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Public Function? (2000)

    A method that hasn't been mentioned is the use of a static variable within your public function. The static variable will hold the value assigned to it until the end of the Access session. Then all you need to do is call the function to retrieve the static value. Something like this will work:

    Public Function StaticValue(optional NewValue as Variant) As Variant
    Static varValue As Variant

    If Not IsMissing(NewValue) Then
    varValue = NewValue
    End If

    StaticValue = varValue
    End Function

    You would set it by passing in a value to the function and retrieve it by calling the function without an argument.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •