dbTalk Databases Forums  

Correctly calling a workday function

comp.databases.ms-access comp.databases.ms-access


Discuss Correctly calling a workday function in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stinky Pete
 
Posts: n/a

Default Correctly calling a workday function - 07-28-2010 , 09:08 PM






Hi,

I tried ages to ago to wrap my head around this process, but I still
need help and education - I found a workaround at the time but it's
come up again. What I want to do is call a function that calcuates
the number of working days between two dates. I've found a function
that makes sense to me, but I'm coming unstuck when calling it from
the form. The code seems to compile OK, but I'm not getting any data
populated in the correct field.

What I need is the [days open] field to show the number of working
days betwen the [Date Initiated] and [Date Complete] when the [Date
Complete] field is populated. Otherwise the [days open] field remains
blank. The intention was to action this "afterupdate".

I've called the function via ...

Call weekdays(startDate, endDate)
startDate = [Date Initiated]
endDate = [Date Complete]

and the first bit of the function as ...

Public Function weekdays(ByRef startDate As Date, _
ByRef endDate As Date _
) As Integer

If anyone needs the rest of the code, I can copy and past it in if
anyone would like it.

Thanx in advance,

Stinky Pete

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Correctly calling a workday function - 07-28-2010 , 09:24 PM






Stinky Pete wrote:

Quote:
Hi,

I tried ages to ago to wrap my head around this process, but I still
need help and education - I found a workaround at the time but it's
come up again. What I want to do is call a function that calcuates
the number of working days between two dates. I've found a function
that makes sense to me, but I'm coming unstuck when calling it from
the form. The code seems to compile OK, but I'm not getting any data
populated in the correct field.

What I need is the [days open] field to show the number of working
days betwen the [Date Initiated] and [Date Complete] when the [Date
Complete] field is populated. Otherwise the [days open] field remains
blank. The intention was to action this "afterupdate".

I've called the function via ...

Call weekdays(startDate, endDate)
startDate = [Date Initiated]
endDate = [Date Complete]

and the first bit of the function as ...

Public Function weekdays(ByRef startDate As Date, _
ByRef endDate As Date _
) As Integer

If anyone needs the rest of the code, I can copy and past it in if
anyone would like it.

Thanx in advance,

Stinky Pete
Wouldn't it work better like
startDate = [Date Initiated]
endDate = [Date Complete]
Call weekdays(startDate, endDate)

When you call the Weekdays() function, it might be start and end are null.

You could even do
Call weekdays([Date Initiated], [Date Complete])

But are you returning anything by using Call that can be assigned to a
control? Something like
Me.DaysWorked = weekdays([Date Initiated], [Date Complete])
would return and assign the value from WeekDays() to the control DaysWorked.

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Correctly calling a workday function - 07-29-2010 , 03:38 AM



On 29/07/2010 03:24:11, Salad wrote:
Quote:
Stinky Pete wrote:

Hi,

I tried ages to ago to wrap my head around this process, but I still
need help and education - I found a workaround at the time but it's
come up again. What I want to do is call a function that calcuates
the number of working days between two dates. I've found a function
that makes sense to me, but I'm coming unstuck when calling it from
the form. The code seems to compile OK, but I'm not getting any data
populated in the correct field.

What I need is the [days open] field to show the number of working
days betwen the [Date Initiated] and [Date Complete] when the [Date
Complete] field is populated. Otherwise the [days open] field remains
blank. The intention was to action this "afterupdate".

I've called the function via ...

Call weekdays(startDate, endDate)
startDate = [Date Initiated]
endDate = [Date Complete]

and the first bit of the function as ...

Public Function weekdays(ByRef startDate As Date, _
ByRef endDate As Date _
) As Integer

If anyone needs the rest of the code, I can copy and past it in if
anyone would like it.

Thanx in advance,

Stinky Pete

Wouldn't it work better like
startDate = [Date Initiated]
endDate = [Date Complete]
Call weekdays(startDate, endDate)

When you call the Weekdays() function, it might be start and end are null.

You could even do
Call weekdays([Date Initiated], [Date Complete])

But are you returning anything by using Call that can be assigned to a
control? Something like
Me.DaysWorked = weekdays([Date Initiated], [Date Complete])
would return and assign the value from WeekDays() to the control
DaysWorked.



I guess that on the AfterUpdate of both the [Date Initiated] and the[Date
Complete] fields as well as on the OnCurrent of the form you need

If not IsNull(Date Initiated] and not IsNull([Date Complete]) then
Me.DaysWorked orked = weekdays([Date Initiated], [Date Complete]) ' Me is not
stricly neccessary as it is a field on the form end If

Incidently, Life is much more simple if you don't have spaces in field names.
You don't need those square brackets I would use DateInitiated an
DateComplete - Just as readable in my opinion

Phil

Reply With Quote
  #4  
Old   
Stinky Pete
 
Posts: n/a

Default Re: Correctly calling a workday function - 07-29-2010 , 08:19 PM



On Jul 29, 6:38*pm, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote:
Quote:
On 29/07/2010 03:24:11, Salad wrote:



Stinky Pete wrote:

Hi,

I tried ages to ago to wrap my head around this process, but I still
need help and education - I found a workaround at the time but it's
come up again. *What I want to do is call afunctionthat calcuates
the number of working days between two dates. *I've found afunction
that makes sense to me, but I'm coming unstuck when calling it from
the form. The code seems to compile OK, but I'm not getting any data
populated in the correct field.

What I need is the [days open] field to show the number of working
days betwen the [Date Initiated] and [Date Complete] when the [Date
Complete] field is populated. *Otherwise the [days open] field remains
blank. The intention was to action this "afterupdate".

I've called thefunctionvia ...

Call weekdays(startDate, endDate)
startDate = [Date Initiated]
endDate = [Date Complete]

and the first bit of thefunctionas ...

PublicFunctionweekdays(ByRef startDate As Date, _
* * ByRef endDate As Date _
* * ) As Integer

If anyone needs the rest of the code, I can copy and past it in if
anyone would like it.

Thanx in advance,

Stinky Pete

Wouldn't it work better like
startDate = [Date Initiated]
endDate = [Date Complete]
Call weekdays(startDate, endDate)

When you call the Weekdays()function, it might be start and end are null.

You could even do
Call weekdays([Date Initiated], [Date Complete])

But are you returning anything by using Call that can be assigned to a
control? *Something like
Me.DaysWorked = weekdays([Date Initiated], [Date Complete])
would return and assign the value from WeekDays() to the control
DaysWorked.

I guess that on the AfterUpdate of both the [Date Initiated] and the[Date
Complete] fields as well as on the OnCurrent of the form you need

If not IsNull(Date Initiated] and not IsNull([Date Complete]) then
Me.DaysWorked orked = weekdays([Date Initiated], [Date Complete]) ' Me is not
stricly neccessary as it is a field on the form end If

Incidently, Life is much more simple if you don't have spaces in field names.
You don't need those square brackets I would use DateInitiated an
DateComplete - Just as readable in my opinion

Phil
Woo hoo. It was a combination of errors, mostly as identified that
the date completed field was null. Whack in the "if not isnull" combo
and voila, life's good again. Well for now, I've still got a heap of
Q's about correctly calling a function, but will deal with them as
required.

Thanx once again.

Stinky Pete

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.