Running A Public Function To Check The Time When A Form Action IsTaken

  • Thread starter nouveauricheinvestments
  • Start date
N

nouveauricheinvestments

Hi,

I would like to be able to check the time when a specific action is
taken on my form before anything else happens. This is the public
function I am trying to use.

Public Function WhatsTheTime() As String

Select Case Time()
Case "> 7:00:00 AM" To "< 3:00:00 PM"
WhatsTheTime = "Day Shift"
Case ">3:00:00 PM" To "<11:00:00 PM"
WhatsTheTime = "Swing Shift"
Case ">11:00:00 PM" To "< 7:00:00 AM"
WhatsTheTime = "Grave Shift"
End Select
End Function


When I try run this from the immediate window by typing Msgbox
WhatsTheTime, It gives me a blank messagebox. What can I do to
determine whether the time of day is between the above increments?
Right now it is 8:00 AM where I am at.

Thanks
 
N

nouveauricheinvestments

hi,



Try Case > #07:00# And < #15:00#.

mfG
--> stefan <--

I tried it exactly as you typed it and it told me there is a Syntax
Error. I tried it like the following and it told me 'Type MisMatch'.

Case "> #07:00#" And "< #15:00#"

I tried the following and it gave me the message box but the message
box was empty

Case "> #07:00#" To "< #15:00#"
 
N

nouveauricheinvestments

I tried it exactly as you typed it and it told me there is a Syntax
Error. I tried it like the following and it told me 'Type MisMatch'.

Case "> #07:00#" And "< #15:00#"

I tried the following and it gave me the message box but the message
box was empty

Case "> #07:00#" To "< #15:00#"

This seems like something that should be so simple - I can't believe I
can't figure it out...
 
D

Dirk Goldgar

Hi,

I would like to be able to check the time when a specific action is
taken on my form before anything else happens. This is the public
function I am trying to use.

Public Function WhatsTheTime() As String

Select Case Time()
Case "> 7:00:00 AM" To "< 3:00:00 PM"
WhatsTheTime = "Day Shift"
Case ">3:00:00 PM" To "<11:00:00 PM"
WhatsTheTime = "Swing Shift"
Case ">11:00:00 PM" To "< 7:00:00 AM"
WhatsTheTime = "Grave Shift"
End Select
End Function


When I try run this from the immediate window by typing Msgbox
WhatsTheTime, It gives me a blank messagebox. What can I do to
determine whether the time of day is between the above increments?
Right now it is 8:00 AM where I am at.


Try this:

Select Case Time()
Case #7:00:00 AM# To #2:59:59 PM#
WhatsTheTime = "Day Shift"
Case #3:00:00 PM# To #10:59:59 PM#
WhatsTheTime = "Swing Shift"
Case #11:00:00 PM# To #6:59:59 AM#
WhatsTheTime = "Grave Shift"
Case Else
WhatsTheTime = "Does anybody really know what time it is?"
End Select
 
S

Stefan Hoffmann

hi,

This seems like something that should be so simple - I can't believe I
can't figure it out...

Public Sub test()

Dim dt As Date

dt = Time()

Debug.Print "TIME"; dt

Select Case dt
Case dt > #5:00:00 PM# And dt < #6:00:00 PM#
Debug.Print "CONDITION"
Case Else
Debug.Print "ELSE"
End Select

End Sub


mfG
--> stefan <--
 
N

nouveauricheinvestments

hi,



Public Sub test()

Dim dt As Date

dt = Time()

Debug.Print "TIME"; dt

Select Case dt
Case dt > #5:00:00 PM# And dt < #6:00:00 PM#
Debug.Print "CONDITION"
Case Else
Debug.Print "ELSE"
End Select

End Sub

mfG
--> stefan <--

Perfect. Dirk's solution worked. The following is what I used.

Public Function WhatsTheTime() As String

Select Case Time()
Case #7:00:00 AM# To #3:00:00 PM#
WhatsTheTime = "Day Shift"
Case #3:00:01 AM# To #11:00:00 AM#
WhatsTheTime = "Swing Shift"
Case #11:00:01 PM# To #7:00:00 AM#
WhatsTheTime = "Grave Shift"
End Select
End Function
 

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