dbTalk Databases Forums  

best way to handle #ERROR in Query

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


Discuss best way to handle #ERROR in Query in the comp.databases.ms-access forum.



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

Default best way to handle #ERROR in Query - 12-22-2009 , 10:25 AM






The following code calcuates the difference in work days between two
dates:

Function BusinessDays(PosHireDate, RepDate) As Long
BusinessDays = (DateDiff("d", PosHireDate, RepDate) - _
(DateDiff("ww", PosHireDate, RepDate) * 2) + 1) + _
(Weekday(PosHireDate) = vbSunday) + _
(Weekday(RepDate) = vbSaturday)
End Function

Date 1 = [PosHireDate] or Position Hire Date
Date 2 = [RepDate] or Report Date

when I execute my query I get "#ERROR" for those records where the
[PosHireDate} is 'blank" or null

My question is,

what is the best way to handle this?

I know the solution is to have a date for each record in the
[PosHireDate], but what about if someone accidently forgets - I still
want it to run, but may have the word "missing" or some huge number
like "1,000" show up.

Thanks!

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

Default Re: best way to handle #ERROR in Query - 12-22-2009 , 10:35 AM






On Dec 22, 10:25*am, jeromez <jeromezilin... (AT) gmail (DOT) com> wrote:
Quote:
The following code calcuates the difference in work days between two
dates:

Function BusinessDays(PosHireDate, RepDate) As Long
BusinessDays = (DateDiff("d", PosHireDate, RepDate) - _
(DateDiff("ww", PosHireDate, RepDate) * 2) + 1) + _
(Weekday(PosHireDate) = vbSunday) + _
(Weekday(RepDate) = vbSaturday)
End Function

Date 1 = [PosHireDate] or Position Hire Date
Date 2 = [RepDate] or Report Date

when I execute my query I get "#ERROR" for those records where the
[PosHireDate} is 'blank" or null

My question is,

what is the best way to handle this?

I know the solution is to have a date for each record in the
[PosHireDate], but what about if someone accidently forgets *- I still
want it to run, but may have the word "missing" or some huge number
like "1,000" show up.

Thanks!
You can trap for a null: If isnull([PosHireDate]) then
BusinessDays = 1000


or you can use NZ: NZ([PosHireDate],Date()) is my favorite in that
it runs but produces an obvious error.


Good luck

Tim

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

Default Re: best way to handle #ERROR in Query - 12-24-2009 , 07:29 AM



On Dec 22, 11:35*am, timmg <tmillsgronin... (AT) gmail (DOT) com> wrote:
Quote:
On Dec 22, 10:25*am, jeromez <jeromezilin... (AT) gmail (DOT) com> wrote:





The following code calcuates the difference in work days between two
dates:

Function BusinessDays(PosHireDate, RepDate) As Long
BusinessDays = (DateDiff("d", PosHireDate, RepDate) - _
(DateDiff("ww", PosHireDate, RepDate) * 2) + 1) + _
(Weekday(PosHireDate) = vbSunday) + _
(Weekday(RepDate) = vbSaturday)
End Function

Date 1 = [PosHireDate] or Position Hire Date
Date 2 = [RepDate] or Report Date

when I execute my query I get "#ERROR" for those records where the
[PosHireDate} is 'blank" or null

My question is,

what is the best way to handle this?

I know the solution is to have a date for each record in the
[PosHireDate], but what about if someone accidently forgets *- I still
want it to run, but may have the word "missing" or some huge number
like "1,000" show up.

Thanks!

You can trap for a null: *If isnull([PosHireDate]) then
* * * BusinessDays = 1000

or you can use NZ: *NZ([PosHireDate],Date()) *is my favorite in that
it runs but produces an obvious error.

Good luck

Tim- Hide quoted text -

- Show quoted text -
Where would this line of code go in my original code:

Quote:
Function BusinessDays(PosHireDate, RepDate) As Long
Quote:
BusinessDays = (DateDiff("d", PosHireDate, RepDate) - _
(DateDiff("ww", PosHireDate, RepDate) * 2) + 1) + _
(Weekday(PosHireDate) = vbSunday) + _
(Weekday(RepDate) = vbSaturday)
End Function

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.