NEED HELP: For this Code

S

Sriram

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
 
B

Bearacade

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top