Results 1 to 8 of 8
  1. #1
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164

    Understanding how to pass a value from form to form

    Hi,

    I'm just learning some VBA.



    I have got a text box to recognise the environ user and display on the start screen.
    I'm not sure how to store that value as a variable for later use.
    I have several uses for this type of scenario, I'm just clued up enough yet on how to set the programming out.
    I presume it will be a Global variable but
    where do I start.

    I have had a mess around but I'm getting lost somewhere.

    Any help, an example or a point in the right direction I would be grateful for the help.






    Sent from my SM-G935F using Tapatalk

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI, for your variables to be accessed from anywhere in VBA, they'd have to be declared in a standard module as public:

    Public VariableName As String

    You've declared them either in a form module or within a sub.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Thanks both for your advice, ill look into the link and create a separate module for setting the variables. (Cheers Pbaldy )

    I'm guessing something like:

    Public Userdetails as string

    Dim Username as string
    Dim Location as string

    UserName = environ ("Username ")
    Etc etc

    From a SUB I then call UserDetails or pass in Me.Textbox = UserDetails.value

    I presume I'm on the right kind of logic.

    Thanks for taking time to reply.





    Sent from my SM-G935F using Tapatalk

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, at its simplest you'd declare the variable in a standard module:

    Public Userdetails as string

    In some procedure:

    Userdetails = environ("Username")

    then when you need it:

    Me.Textbox = UserDetails

    The TempVars method orange mentioned is another alternative, and offers the advantage of being able to be used directly in queries or macros (I think, I don't use them). I was simply trying to educate as to why what you were trying wasn't working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    No problem with the suggestions, but I see that you seem to know how to create a class for contact and customer. Why not create a class for user? You could create user class properties such as FName, Lname, EmplNo, Email, LoginId, UsrLevel, etc, etc.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    djspod is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    164
    Hi Micron,

    Thanks for your reply

    I inherited the DB from a YouTube user so I did not create or use the Class files.
    I will let look into that to gain more upstanding of Class, Module and SUB Procedures.

    And what difference is between using each and what the benefits are.

    Thanks for your help

    Sent from my SM-G935F using Tapatalk

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    djspod,

    Thanks for responding. I had the same question as Micron re class modules.
    Good luck with your project.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-02-2016, 08:20 AM
  2. Replies: 1
    Last Post: 06-03-2016, 08:23 PM
  3. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  4. Replies: 7
    Last Post: 03-11-2015, 12:48 PM
  5. Understanding the Form width property
    By Access_Novice in forum Forms
    Replies: 5
    Last Post: 01-18-2014, 07:03 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