Display a value in a recordset on my form

MsLady

Traumatized by Access
Local time
Yesterday, 16:29
Joined
Jun 14, 2004
Messages
438
I have a table that contains fields as follows: [userId], [userName], [userFullname]. About 10 users (records) in total.

I have a function username() that gets the username of a user from their logon.

Now on my form, i have a textbox that I'd like to display the Fullname of the user that's currently logged on the form (On Open event). Meaning, it will get their username from my function, then compare it to values in the users table and display the full name of the user when the user opens to form to view their records.

Can anyone enlighten me on how to do this. I have tried tried tried, my methods aren't getting me anywhere.

Any help, suggestions, ideas will be greatly appreciated!
 
I assume that you want to keep the person's name on the form, no matter where he goes in the underlying recordset.

Create a query using the function as the criteria. Then, in the form, open a recordset of that query. You should get only one record. Then set the caption of a label to the user's full name as concatinated from the first and last name coming out of the query's recordset. Or, you could create the recordset from SQL you write in vba. Again, you would use the function to set the criteria.
 
You are the best!!! :D

Code:
Public Function GetUserFullName() As String
    Dim db As Database
    Dim rs As dao.Recordset
    Dim strSQL As String
    Dim LUser As String
    
    Set db = CurrentDb()
    strSQL = "SELECT operatorFullName FROM tblOperator WHERE [operatorUsername]=username();"
    Set rs = db.OpenRecordset(strSQL)

    If rs.EOF = False Then
        LUser = rs("operatorFullName")
    End If

    rs.Close
    Set rs = Nothing

    GetUserFullName = LUser
End Function

Then i call the function GetUserFullName() from the control source on my form. Works like charm!!! Thanks darling.
 

Users who are viewing this thread

Back
Top Bottom