• passing values using global

    Author
    Topic
    #463287

    working on this at the moment, thought i’d swing by the lounge…

    in the Login form, there’s this:

    Code:
    Option Compare Database
    Public globalUserID As String
    Public globalClassification As String
    Option Explicit

    the var gets loaded here:

    Code:
    		
    Public Sub cmd_OK_Click()
    ... logic to confirm/deny login...
    globalUserID = rsLogin("USER_ID").Value
    		globalClassification = rsLogin("Classification").Value
    		DoCmd.Close acForm, "Login"
    		'DoCmd.OpenForm "Background"
    		DoCmd.OpenForm "RUG"
    End Sub

    As you can see, the login form is closed and control is passed to the form RUG. in “On Load” I try this:

    Code:
    Dim globalUserID As String
    MsgBox "Welcome, " & globalUserID

    Do i need to call the public function from the Login? I tried that and it says “Sub or Function Not Defined”.

    All I want to do is capture the logged in user’s ID in memory and, once the edits are processed and finalized by the user, write that value to the underlying table(s) that handle the edits.

    TIA

    Viewing 2 reply threads
    Author
    Replies
    • #1182187

      working on this at the moment, thought i’d swing by the lounge…

      in the Login form, there’s this:

      Code:
      Option Compare Database
      Public globalUserID As String
      Public globalClassification As String
      Option Explicit

      the var gets loaded here:

      Code:
      		
      Public Sub cmd_OK_Click()
      ... logic to confirm/deny login...
      globalUserID = rsLogin("USER_ID").Value
      		globalClassification = rsLogin("Classification").Value
      		DoCmd.Close acForm, "Login"
      		'DoCmd.OpenForm "Background"
      		DoCmd.OpenForm "RUG"
      End Sub

      As you can see, the login form is closed and control is passed to the form RUG. in “On Load” I try this:

      Code:
      Dim globalUserID As String
      MsgBox "Welcome, " & globalUserID

      Do i need to call the public function from the Login? I tried that and it says “Sub or Function Not Defined”.

      All I want to do is capture the logged in user’s ID in memory and, once the edits are processed and finalized by the user, write that value to the underlying table(s) that handle the edits.

      TIA

      I could be wrong, but I think that Public variables and Constants cannot be declared in a Forms Private Module and then referenced after the form is closed.

      You would need to define the Public variables in a Module and then write data to them from within the form.
      Then once the form is closed hey will still be in scope

    • #1182189

      Andrew is correct – you want to define the Global value in a module, but you don’t want to define it again in another module. The bigger question is instead of reinventing the wheel by devising your own login process, why not either capture the Windows login, or activate Access User Security and use that login? There are a number of threads on both techniques in the Lounge.

    • #1182207

      I was thinking I had to move the code to a regular module. will do that.

      Wendell, as to your suggestion to do something more interesting like capture the network userid or something along those lines, i originally thought that would be a better option, but the access project i am building will be used off-line, as it were, so I don’t think the network login data would be available. Anyway, there’s already a pre-defined table for id’s, passwords and roles so I opted to use that instead. I don’t like working with Access roles and securities, always found that to be a bit too confusing. I *am* blonde, you know.

    Viewing 2 reply threads
    Reply To: passing values using global

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: