Time Select Case

G

Guest

I am trying to write a select case for a certain time. I have in a table, 5
starting times, in which I have different factors to apply to the data based
on what time the data was collected. My problem is in I can get the time for
the data, but the select case blows by the time . Here is my code.

Option Explicit

dim BegHr as Date
dim FactorSet as String

BegHr = DFirst ([field],some table,id#=id# in some form)
Debug.Pring BegHr = 10:00:00 AM

select case BegHr

Case BegHr = #10:00:00 AM#
FactorSet = "Set1"

When I run the program, it blows right by the Case and doesn't set
FactorSet. Am I not using the correct Date/Time properties? Thanks.

Kou
 
J

John W. Vinson

I am trying to write a select case for a certain time. I have in a table, 5
starting times, in which I have different factors to apply to the data based
on what time the data was collected. My problem is in I can get the time for
the data, but the select case blows by the time . Here is my code.

Option Explicit

dim BegHr as Date
dim FactorSet as String

BegHr = DFirst ([field],some table,id#=id# in some form)
Debug.Pring BegHr = 10:00:00 AM

select case BegHr

Case BegHr = #10:00:00 AM#
FactorSet = "Set1"

When I run the program, it blows right by the Case and doesn't set
FactorSet. Am I not using the correct Date/Time properties? Thanks.

A Date/TIme value is stored as a Double Float number, a count of days and
fractions of a day (times) since midnight, December 30, 1899. As such, a time
is accurate to well under a microsecond - and the SELECT CASE may be missing
by that 0.00000002 seconds!

Try using a string conversion: if the time is accurate only to a minute, say

Dim strBegHr As String
strBegHr = Format(DFirst("[field]", "[some table]", _
"[ID#]=" & Forms!SomeForm!ID), "hh:nn")
Select Case strBegHr
Case "10:00"
FactorSet = "Set1"
Case "12:00"
FactorSet = "Set2"
Case "14:00"
FactorSet = "Set3"
Case Else
<do something for unmatched values>
End Select

Note that DFirst() may not be doing what you expect: it will NOT give you the
earliest time in the table for that ID. It will give you the first qualified
record *in disk storage order* - and you have no guarantee that the disk
storage order is chronlogical or logical in any sense, as Access will store
records wherever it finds it convenient. You might want DMin() instead.

John W. Vinson [MVP]
 
M

missinglinq via AccessMonster.com

I really not clear on exactly what it is you're trying to do, but I think

Case BegHr = #10:00:00 AM#

should be simply

Case BegHr #10:00:00 AM#

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

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