PC Review


Reply
Thread Tools Rate Thread

Dtermine the Period

 
 
=?Utf-8?B?RXJpYw==?=
Guest
Posts: n/a
 
      4th Feb 2005
Hi,
I have 1 Table "Periods" with 3 fields:
From date - To date - Period
01/01/2004- 02/02/2004 - 01
03/02/2004- 02/03/2004 - 02 ..........
I have 13 periods.

In my Form I have a field "Date" and a field "Period"
I would like when user type the "Date", it giving automatically the exact
period from the Table.
I did it with this formula but doesn't work perfectly, is the a simply way
to do it ?

(If Me![Date] >= "2004/04/01" And Me![Date] <= "2004/05/01" Then
Me![Periode] = 1
End If )

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U0hJUFA=?=
Guest
Posts: n/a
 
      4th Feb 2005
Here's a function that will calculate the period for you. Simply call it from
anywhere and supply the date.



Option Compare Database
Option Explicit

Public Function intPeriod(dtmCurrent As Date) As Integer



On Error GoTo HandleErr
Const cstrProcName As String = "stdCalcPeriod - intPeriod"

Dim intJDay As Integer
Dim dblPeriod As Double
Dim intPer As Integer
Dim Jan31WkDay As Integer
Dim intYear As Integer
Dim Jan31TheYear As Date
Dim intPerStart As Integer

intJDay = DatePart("Y", dtmCurrent)
intYear = DatePart("YYYY", dtmCurrent)
Jan31TheYear = DateSerial(intYear, 1, 31)
Jan31WkDay = DatePart("W", Jan31TheYear)
Select Case Jan31WkDay
Case 1
intPerStart = 31
Case 2
intPerStart = 30
Case 3
intPerStart = 29
Case 4
intPerStart = 28
Case 5
intPerStart = 27
Case 6
intPerStart = 26
Case 7
intPerStart = 32
End Select
dblPeriod = ((((intPerStart - 28) * -1) + intJDay) / 28) + 1
intPer = Fix(dblPeriod)
Select Case intPer
Case Is < 1
intPeriod = 13
Case Is > 13
intPeriod = 13
Case Else
intPeriod = intPer
End Select

ExitHere:
Exit Function

HandleErr:
intPeriod = 0
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select
Resume ExitHere

End Function


"Eric" wrote:

> Hi,
> I have 1 Table "Periods" with 3 fields:
> From date - To date - Period
> 01/01/2004- 02/02/2004 - 01
> 03/02/2004- 02/03/2004 - 02 ..........
> I have 13 periods.
>
> In my Form I have a field "Date" and a field "Period"
> I would like when user type the "Date", it giving automatically the exact
> period from the Table.
> I did it with this formula but doesn't work perfectly, is the a simply way
> to do it ?
>
> (If Me![Date] >= "2004/04/01" And Me![Date] <= "2004/05/01" Then
> Me![Periode] = 1
> End If )
>
> Thanks

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      4th Feb 2005
"=?Utf-8?B?RXJpYw==?=" <(E-Mail Removed)> wrote in
news:32A516D6-130A-4C33-9A69-(E-Mail Removed):

> Hi,
> I have 1 Table "Periods" with 3 fields:
> From date - To date - Period
> 01/01/2004- 02/02/2004 - 01
> 03/02/2004- 02/03/2004 - 02 ..........
> I have 13 periods.
>


'
' Create the criterion carefully: note proper formats
' By the way, using names like "Date" is a Really Bad Idea
' So is using table names and field names with spaces in them
'
strWhere = _
"FromDate <= " & format(Me!DateControl,"\#yyyy\-mm\-dd\#") & _
" AND ToDate >= " & format(Me!DateControl,"\#yyyy\-mm\-dd\#")

'
' check it looks okay; remove this line once it's debugged
'
msgbox strWhere

'
' look up result
'
wPeriod = DLookup("Period", "Schedules", strWhere)


There is probably a neater way using Max(), but this is easy to maintain
and to understand.

Hope it helps


Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dtermine when an unshelled process has finished RichardGarfield General Software 0 18th May 2011 11:44 AM
dtermine row/column boundaries of selected area John Keith Microsoft Excel Programming 5 3rd Jun 2009 04:34 AM
can't dtermine the problem kaspr79 Computer Hardware 4 9th Jun 2006 08:58 PM
Need VBA code to dtermine how many rows have data in them Shani Microsoft Excel Programming 4 13th Apr 2006 05:17 PM
In IRR period in data flow compared to period in result percentage =?Utf-8?B?SkNO?= Microsoft Excel Worksheet Functions 7 2nd May 2004 02:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.