Results 1 to 3 of 3
  1. #1
    sheusz is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2015
    Posts
    151

    Exclamation Display a field value in Message Box text.

    I would like to display a field value in the text of a message box.



    For example That user is already logged in on fieldname

    I have a login form that asks for a UserName and Password and records this to a table together with the workstation name and workstation userlogin. This is because we have roaming profiles on our network so any user can log in to the network from any workstation.

    What I want to prevent is the same user having simultaneous logins on different workstations.

    When a user enters their UserName and Password, the login form checks to see if they are already logged in to the database on a different workstation. If they are, a message box pops up telling them that they are already logged in (see code below).

    Code:
    If DLookup("LoginUsername", "tblLogger", "LoginUsername = '" & LoginUserName & "'" & "AND IsNull([Logout])") > 0 Then
    
         MsgBox LoginUserName & " is already logged in." & Chr(13) & "Program will now close.", vbInformation, "Login Error"
              
         Else
    
         MsgBox "User " & LoginUserName & " is not logged in", vbInformation, "Login Success"
    End If
    This works but I think is lazy and I like to make message boxes actually useful.

    I want the message box to display on which terminal the user is already logged. eg.

    John Smith is already logged in on workstation 5.

    The field ComputerName is in the table Logger and it is this field that I want to add to the message box text.

    Simple yes?

    Can anyone point out the correct syntax to do this please?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    DLookup returns Null if no match.

    Do another DLookup().

    DLookup("ComputerName", "tblLogger", "LoginUserName='" & LoginUserName & "' AND IsNull([Logout])")
    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.

  3. #3
    sheusz is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2015
    Posts
    151
    Hi June7

    Thank you for the reply. I thought that I might have to do that. Your solution worked perfectly.

    For the future reference of other visitors, here is the code for the Login Screen sub.

    Code:
    Private Sub Command1_Click()
    ' Login Screen
    
    If IsNull(Me.txtLoginID) Then
        MsgBox "Please enter Login ID", vbInformation, "Login ID Required"
        Me.txtLoginID.SetFocus
        ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please enter Login Password", vbInformation, "Login Password Required"
        Me.txtPassword.SetFocus
    Else
        
        ' Continue. Check that user exists.
            
        If (IsNull(DLookup("WebUsername", "xEmployees", "StrComp(WebUsername, '" & Me.txtLoginID.Value & "', 0) = 0 AND StrComp(WebPassword, '" & Me.txtPassword.Value & "', 0) = 0"))) Then
            MsgBox "Incorrect Login ID or Password", vbInformation, "Login Details Incorrect"
            
            Else
            
            'Continue and check that the user isn't already logged in on another terminal
            
            LoginUserName = (DLookup("Firstname", "xEmployees", "WebUsername ='" & Me.txtLoginID.Value & "'")) & " " & (DLookup("Surname", "xEmployees", "WebUsername ='" & Me.txtLoginID.Value & "'"))
            
            If DLookup("LoginUsername", "Logger", "LoginUsername = '" & LoginUserName & "'" & "AND IsNull([Logout])") > 0 Then
                Dim OnComputer As String
                OnComputer = DLookup("ComputerName", "Logger", "LoginUserName='" & LoginUserName & "' AND IsNull([Logout])")
    
                MsgBox LoginUserName & " is already logged in on " & OnComputer & Chr(13) & "Program will now close.", vbInformation, "Login Error"
    
                DoCmd.Quit
                
                Else
                'All good to proceed
         
                AccessLvl = (DLookup("DBAccessLvl", "xEmployees", "WebUsername ='" & Me.txtLoginID.Value & "'"))
                DoCmd.Close
                MsgBox "Welcome " & LoginUserName & Chr(13) & "Access Level: " & AccessLvl, vbInformation, "Sucessfully Logged In"
                DoCmd.Close
                DoCmd.OpenForm "Main Screen"
            End If
    
        End If
        
    End If
      
    End Sub

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

Similar Threads

  1. Message Box Display if Field is Null
    By dhicks in forum Forms
    Replies: 19
    Last Post: 07-14-2017, 01:54 PM
  2. display a message in a text box
    By mmaule in forum Access
    Replies: 2
    Last Post: 02-18-2015, 11:14 AM
  3. Replies: 9
    Last Post: 04-18-2014, 08:51 PM
  4. Display field as text box
    By thekruser in forum Forms
    Replies: 5
    Last Post: 08-31-2010, 10:37 AM
  5. Replies: 1
    Last Post: 03-02-2006, 06:17 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