Results 1 to 5 of 5
  1. #1
    joshynaresh is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    131

    retrieve value from another form

    suppose i have 2 form calle loginpage and swithcboard.
    i want
    when i login from loginpage user id value should be wrote in userid field of switchbord form.
    Can it is possible.

    Thanks in advance

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I like to do the same thing. I will store the UserID in an unbound textbox in a form that always remains open. My approach to this is a little complicated. I start by creating a public variable in a general module. This way I have a variable I can pass the UserID from form to form with, regardless of which form the user may be using.

    I start by declaring a variable in a general module.

    Code:
    'Declare variable for UserID
    Public glngDeptID As Long
    Then I put some code in the logon form. This form will likely be the first form your user sees.

    Code:
        If Not IsNothing(Me.cmbUserID.Column(0)) Then
        
            glngDeptID = Me.cmbUserID.Column(0)
            DoCmd.OpenForm "frmMain", acNormal
            DoCmd.Close acForm, "frmSplash"
        
        Else
        Exit Sub
        End If
    Now that the UserID value is in the public variable, I can pass it to the unbound textbox in my frmMain. This form remains open while the application is open. In this form's "Load" event, I place the following.

    Code:
    If Not IsNull(glngDeptID) Then
    Me.txtDeptID.Value = glngDeptID
    Else
    Me.txtDeptID.Value = ""
    End If
    Now that the textbox has the UserID/DeptID, I can grab this value from anywhere within my app. I don't have to wory about the variable losing its value. Each time I need to use the UserID, I reassign the variable the UserID value in THAT form's load event, just before I need it.

    Code:
    If Not IsNull(Forms!frmMain![txtDeptID]) Then
    glngDeptID = Forms!frmMain![txtDeptID] 'Remind Access what the DeptID is
    Else
    glngDeptID = ""
    End If
    Doing it this way helps in cases your users have a full version of access installed and your program does not shut down in cases of runtime errors. If the variable loses its value it may be helpful to assign it again.

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Are you using a command button to get from the login page to the switchboard form?

    If so, then add lines of code to your command button

    Code:
    Dim txtLogIn as Variant
    txtLogIn = LogInField.Value
    
    Your Code to Open Switchboard
    
    UserIDField.Value = txtLogIn
    
    Your remaining Code
    
    End Sub

  4. #4
    joshynaresh is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    131
    first Login page open. if userID and Password is correct then Set Date form open. on set Date form after date updated then switchboard open.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Be careful with global public variables. They can be a headache during debugging. If code is interrupted, the variable loses its value.

    I store the user login on a form that never closes (like the 'main menu') then I just reference control on 'main menu' from anywhere.


    As you can see from responses here and in your other thread https://www.accessforums.net/forms/g...orm-38829.html there is more than one way to accomplish passing data between forms.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 07-26-2013, 12:10 PM
  2. Replies: 3
    Last Post: 01-09-2013, 03:39 PM
  3. Submit and retrieve data in a form
    By Bertrand82 in forum Import/Export Data
    Replies: 1
    Last Post: 10-05-2012, 11:44 AM
  4. Replies: 1
    Last Post: 03-09-2012, 07:43 PM
  5. Retrieve old e-mail through an Access form?
    By jimmonator in forum Forms
    Replies: 1
    Last Post: 05-12-2011, 04:34 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