Adding User name to Opening Form and Recording

D

DDrowe

Is there a way that when the user signs in, the opening form that he/she will
use will say something like "Welcome Bob. What would you like to do today?"

I would also like to capture this user with a time stamp to be able to see
who is and was accessing the program.

Thanks

David
 
D

DDrowe

I am still learning all this. Once I have put this into the program as a new
module. How do I make it show up in a table or on the opening form?

Thanks

David
 
R

Rob Oldfield

It depends what you want to do with it, but you can pretty much use the
function wherever you want to set some text. For example:

Private Sub Form_Open(Cancel As Integer)
'Set the caption of the form...
Me.Caption = "Welcome " & fOSUserName

'...or set the content of a text box
Me.txtUserName = fOSUserName

'...or build and execute an SQL statement to log that the form has been
opened
Dim sql As String
sql = "Insert into Log (UserName, Action, When) " & _
"Values ('" & fOSUserName & "','Entered',Now())"
Dim db As Database
Set db = CurrentDb
db.Execute sql, dbFailOnError
Set db = Nothing
End Sub
 
T

Todd K.

This works great, but now I want to have a message box pop up that is user
specific. I tried:

IF fOSUserName NOT IN ("DLG-Bob.Jones","DLG-Jenny.Jones") THEN msgbox...

but it would not recognize the word "in". Then I tried:

IF (Eval("fOSUserName NOT IN (""DLG-Bob.Jones"",""Jenny.Jones"")")) THEN
MsgBox...

but it said it cannot find fOSUserName. What is the correct code for this
IF/THEN statement?
 
T

Todd K.

Nevermind, I figured it out using a Select Case statement. You can use lists
with Case:

Select Case fOSUserName
Case "DLG-Bob.Jones","DLG-Jenny.Jones"
msgbox...
End Select
 
Top