NEED HELP: For this Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Friends,

See below my code and it is not coming as desired. Kindly resolve this please.

Private Sub UserForm_Activate()

Dim Wish As String
Dim Cur_Time As Date
Dim Cur_User As String

Cur_Time = Time

'Label1.Caption = Cur_Time

If Cur_Time >= "12:00:00AM" And Cur_Time < "12:00:00PM" Then
Wish = "Good Morning"
ElseIf Cur_Time >= "12:00:00PM" And Cur_Time < "3:00:00PM" Then
Wish = "Good Afternoon"
ElseIf Cur_Time >= "3:00:00PM" And Cur_Time < "12:00:00AM" Then
Wish = "Good Evening"
Else: Wish = "NULL"
End If

Label1.Caption = Cur_Time & " - " & Wish


End Sub

It displays the current time with Wish data as NULL.

Kindly let me know about the mistake I did.

Thanks and Regards,
Sriram Subramaniyan
 
add spaces before the AM and PM

Private Sub UserForm_Activate()

Dim Wish As String
Dim Cur_Time As Date
Dim Cur_User As String

Cur_Time = Time

'Label1.Caption = Cur_Time

If Cur_Time >= "12:00:00 AM" And Cur_Time < "12:00:00 PM" Then
Wish = "Good Morning"
ElseIf Cur_Time >= "12:00:00 PM" And Cur_Time < "3:00:00 PM" Then
Wish = "Good Afternoon"
ElseIf Cur_Time >= "3:00:00 PM" And Cur_Time < "12:00:00 AM" Then
Wish = "Good Evening"
Else: Wish = "NULL"
End If

Label1.Caption = Cur_Time & " - " & Wish


End Sub
 
Back
Top