Results 1 to 6 of 6
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Question Session variables

    I have a login form and I am wondering if the loginID can be saved in a session variable so that it is available to use in other forms.

    Right now, I have declared a global variable and assigned the global variable to a local variable in the afterUpdate function of the UserName comboBox in the login page. In the next page, I need to use the loginID, so I have assigned another local variable to the global variable.



    For example,

    globalVariable = me.form1Combo1.value

    me.form2textbox1.value = globalVariable

    Now, I need to use the loginID in another page, so I am wondering if the only solution is to again assign the global variable to a local variable in the afterUpdate function or if there is a simpler solution.

    I am thinking of a session variable where I can access the loginID in every page. I have done this in java. Not sure of how to acheive it in vba.

    Any help would be greatly appreciated

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    accessnewb -

    I don't have much experience with Global Variables, but, in situations like this, I have used arrays very successfully.

    If you don't have a module named Arrays, create one. Add this code:

    Option Compare Database

    Public arrUSR(0) As Variant

    Then, in the afterUpdate event of the combo, set the arrays value...

    arrUSR(0) = me.Combo1


    Thereafter, you can grab its value whenever its needed, like...

    me.textbox1 = arrUSR(0)

    The value of arrUSR(0) will be available while access is open.

    Hope this helps,

    Jim

  3. #3
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    oooh, it works! Thanks a bunch. Phew! saved me a lot of time

  4. #4
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm, why doesnt it work when u declare a string instead of an array? just curious

  5. #5
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    accessnewb -

    Don't know why? Maybe it was declared or referenced incorrectly? Without seing the db, its hard to speculate.

    However, I'm glad you got it to work. As I said, I have always had very good luck using arrays.

    All the best,

    Jim

  6. #6
    AndreT is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    25
    I created a form to store/display all these session variables and set its visible property to no. During debugging, I open it up and check if everything's OK.

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

Similar Threads

  1. VBA variables in SQL
    By compooper in forum Programming
    Replies: 3
    Last Post: 07-06-2011, 11:04 AM
  2. Replies: 6
    Last Post: 11-18-2010, 04:00 AM
  3. VBA in variables
    By smikkelsen in forum Access
    Replies: 3
    Last Post: 11-12-2010, 03:14 PM
  4. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 PM
  5. Replies: 0
    Last Post: 11-28-2005, 01:04 AM

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