How to concatenate in VBA Ms Access
I want to concatenate the code below so that whoever is loged in my software is addressed by the username, any idea? I want to add Environ("Username")
on the code below:
Private Sub Form_Activate()
'When the database is opened display welcome user message.
If Time() < 0.5 Then
[lblMorning].Visible = True
[lblAfternoon].Visible = False
[lblEvening].Visible = False
ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = True
[lblEvening].Visible = False
ElseIf Time() > 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = True
End If
End Sub
on the code below:
Private Sub Form_Activate()
'When the database is opened display welcome user message.
If Time() < 0.5 Then
[lblMorning].Visible = True
[lblAfternoon].Visible = False
[lblEvening].Visible = False
ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = True
[lblEvening].Visible = False
ElseIf Time() > 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = True
End If
End Sub
BTW, rather than having three separate labels, you might want to consider a single label, and then just change the Caption property of the label to reflect the time of day and the users name, based on the Time() value.
ASKER
All I need is just how to concatenate the code like
[lblMorning].Visible = True & " "Environ("Username")
But is give me an error
Regards
Chris
[lblMorning].Visible = True & " "Environ("Username")
But is give me an error
Regards
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or:
Private Sub Form_Activate()
' When the database is opened display welcome user message.
Dim Caption As String
Caption = "Welcome " & Environ("Username") & "!"
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = False
Select Case Time
Case < #12:00:00#
[lblMorning].Visible = True
[lblMorning].Caption = Caption
Case < #18:00:00#
[lblAfternoon].Visible = True
[lblAfternoon].Caption = Caption
Case Else
[lblEvening].Visible = False
[lblEvening].Caption = Caption
End Select
End Sub
Environ can be spoofed, which is why many developers use the API call instead.
[lblMorning].Visible = True & " "Environ("Username")
The visible property of the control must have either a True or False value. you might want to concatenate the username to the caption, with something like:
me.[lblMorning].Caption = me.[lblMorning].Caption & " " & Environ("UserName")
[lblMorning].Visible = True & " "Environ("Username")
The visible property of the control must have either a True or False value. you might want to concatenate the username to the caption, with something like:
me.[lblMorning].Caption = me.[lblMorning].Caption & " " & Environ("UserName")
You can find the code here: http://theaccessweb.com/api/api0008.htm
Then, you would store those values in a table (users or employees or something like that) and use the value returned by the function to return the actual name of the user rather then their login username.