Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    4

    Unanswered: Retreive value from other form

    Hi,

    I have a login form in my database where the user enters their username into a textbox and their password in the same way. The system then verifies the data against the records in the related entity. This all works fine.

    However, I have a problem. When they login, if the login is successful, a new form opens and the login form closes. On the form which opens I want to display the name of the user who just logged in. I have searched many times but have not found anything similar.

    Basically, I want to display the value entered into a textbox on one form on a separate form.

    Thanks in advance,

    Paul Moscrop.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    look at the current user function

    alternatively save yourself a bundle of effort and user the newtork API calls to find the network logon userid
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2011
    Posts
    4
    Hi,

    Thanks for the reply on my thread. My login system was created by myself using VBA code.

    Private Sub Login_Click()


    ' Check value in Username field matches that of the value in the tblUser entity
    If IsNull(Me.Username) Or Me.Username = "" Then
    MsgBox "Please enter your Username", vbOKOnly, "School Monitoring System"
    Me.Username.SetFocus

    Exit Sub
    End If


    ' Check value in Password field matches that of the value in the tblUser entity
    If IsNull(Me.Password) Or Me.Password = "" Then
    MsgBox "Please enter your Password", vbOKOnly, "School Monitoring System"
    Me.Password.SetFocus

    Exit Sub
    End If

    If Me.Password.Value = DLookup("Password", "tblUser", "Username='" & Me.Username.Value & "'") Then

    ' Check to see if the users account is suspended
    If DLookup("AccountSuspended", "tblUser", "Username='" & Me.Username.Value & "'") Then
    MsgBox "Your account is suspended - please contact the system administrator", vbOKOnly, "School Monitoring System"
    DoCmd.Quit
    Exit Sub
    End If

    Username = Me.Username.Value

    ' Checks to see what Permission Level the user has
    If DLookup("[Permission Level]", "tblUser", "[Username]='" & Me.Username.Value & "'") = 1 Then
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmTeacher"
    Exit Sub
    End If

    If DLookup("[Permission Level]", "tblUser", "[Username]='" & Me.Username.Value & "'") = 2 Then
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmHeadofDept"
    Exit Sub
    End If

    If DLookup("[Permission Level]", "tblUser", "[Username]='" & Me.Username.Value & "'") = 3 Then
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmHeadteacher"
    Exit Sub
    End If

    If DLookup("[Permission Level]", "tblUser", "[Username]='" & Me.Username.Value & "'") = 4 Then
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmAdmin"
    Exit Sub
    End If


    Else

    If DCount("Username", "tblUser", "Username='" & Me.Username.Value & "'") > 0 Then

    Dim UpdateIncorrectCounter As String
    Dim IncorrectLogins As Integer

    IncorrectLogins = DLookup("IncorrectLogins", "tblUser", "Username='" & Me.Username.Value & "'") + 1
    UpdateIncorrectCounter = "UPDATE tblUser SET IncorrectLogins = " & IncorrectLogins & " WHERE Username = '" & Me.Username.Value & "'"

    If IncorrectLogins >= 3 Then
    DoCmd****nSQL "UPDATE tblUser SET AccountSuspended = True WHERE Username = '" & Me.Username.Value & "'"
    End If

    DoCmd.SetWarnings False
    DoCmd****nSQL UpdateIncorrectCounter


    MsgBox "Incorrect password - please try again", vbOKOnly, "School Monitoring System"
    Me.Password.SetFocus

    End If

    End If
    End Sub

    That is the code. When the new form opens (frmTeacher) I want it to display the value which was entered in the form which closes (frmLogin) using the Username textbox.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ok so declare a (public) global variable in a module
    assign the value of the userid to that global variable
    then refer to that variable as and when you need it.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Aug 2011
    Location
    Indianapolis, IN, USA
    Posts
    41
    I think what you want to do is pass the information as an OpenArgs property.

    For Example: docmd.openform "formname",,,,,,"InfotoPass"

    That's six commas.

    In the on load event of the form that you open, you can retrieve the information from the OpenArgs property.

    Forgive me if I've misunderstood your problem.

Posting Permissions

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