Interesting query problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DeanL

    #1

    Interesting query problem

    Hi all,

    I have a problem that I'm a little stumped by and need some help if
    possible. I need to generate a report in Access 97 from 2 tables (easy
    so far) but it requires a calculated date based on several factors
    including whether a date is present in one of three fields.

    Basically, I have 3 date fields (Award Date, RTL Date and Target RTL
    Date) each of which may or may not contain a date. I need to use the
    Award Date if present, if not then the RTL Date and if that's missing
    then the Target RTL Date and then count X number of days forward from
    that date based on a Cost field (below A then count 6 weeks forward,
    below C but above C then count 8 weeks forward, etc.). If the Award
    Date is present then that would be used otherwise the RTL Date and
    Target RTL Date would be used to calculate an Estimated Award Date
    based on other criteria.

    There are a number of instances where there may be no date at all, in
    which case I just want to show a basic message.

    Any help would be very much appreciated.

    Many thanks, Dean...

  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Interesting Problem

    Originally posted by DeanL
    Hi all,

    I have a problem that I'm a little stumped by and need some help if
    possible. I need to generate a report in Access 97 from 2 tables (easy
    so far) but it requires a calculated date based on several factors
    including whether a date is present in one of three fields.

    Basically, I have 3 date fields (Award Date, RTL Date and Target RTL
    Date) each of which may or may not contain a date. I need to use the
    Award Date if present, if not then the RTL Date and if that's missing
    then the Target RTL Date and then count X number of days forward from
    that date based on a Cost field (below A then count 6 weeks forward,
    below C but above C then count 8 weeks forward, etc.). If the Award
    Date is present then that would be used otherwise the RTL Date and
    Target RTL Date would be used to calculate an Estimated Award Date
    based on other criteria.

    There are a number of instances where there may be no date at all, in
    which case I just want to show a basic message.

    Any help would be very much appreciated.

    Many thanks, Dean...
    The value of your Calculated Field will be the return value of a Public Function. The logic goes something like this, in the Calculated Field within the
    QBE Grid:
    CalcField:fAnyName([Award Date], [RTL Date], [Target RTL Date], _
    [Cost])

    The actual function would be something like this:
    Public Function fAnyName(AwardD ate As Date, RTLDate As Date, TargetRTLDate As Date, MyCost As Currency)

    If IsNull(AwardDat e) AND IsNull(RTLDate) AND IsNull(TargetRT LDate) Then
    Msgbox "Some Message"
    fAnyName = NULL
    Exit Function
    End If

    If Not IsNull(AwardDat e) Then
    'use Awarddate in calculations
    fAnyName = <RetVal>
    Else 'AwardDate is Null
    If Not IsNull(RTLDate) Then
    'use RTLDate in calculations
    fAnyName = <RetVal>
    Else
    If Not IsNull(TargetRT LDate) Then
    'use TargetRTLDate in calculations along with the passed Cost
    'Argument
    fAnyName = <RetVal>
    Else
    fAnyName = <RetVal>
    End If
    End If
    End If

    Hopes this helps and does not confuse!!!

    Comment

    • Bob Quintal

      #3
      Re: Interesting query problem

      "DeanL" <deanpmlonghurs t@yahoo.com> wrote in
      news:1149032065 .455171.111980@ v35g2000cwv.goo glegroups.com:
      [color=blue]
      > Hi all,
      >
      > I have a problem that I'm a little stumped by and need some
      > help if possible. I need to generate a report in Access 97
      > from 2 tables (easy so far) but it requires a calculated date
      > based on several factors including whether a date is present
      > in one of three fields.
      >
      > Basically, I have 3 date fields (Award Date, RTL Date and
      > Target RTL Date) each of which may or may not contain a date.
      > I need to use the Award Date if present, if not then the RTL
      > Date and if that's missing then the Target RTL Date and then
      > count X number of days forward from that date based on a Cost
      > field (below A then count 6 weeks forward, below C but above C
      > then count 8 weeks forward, etc.). If the Award Date is
      > present then that would be used otherwise the RTL Date and
      > Target RTL Date would be used to calculate an Estimated Award
      > Date based on other criteria.
      >
      > There are a number of instances where there may be no date at
      > all, in which case I just want to show a basic message.
      >
      > Any help would be very much appreciated.
      >
      > Many thanks, Dean...
      >
      >[/color]
      This sounds like you need a user defined function more than a
      query, because the logic just gets too convoluted. You can then
      call the udf in the query, or in the report itself.


      Off the top of my head, this should do what you want.
      public function CalcDate( dtAward, DtRTL, DtEstm, AmtCost) as
      variant.

      If not IsNull(dtAward) then
      Calcdate = dtAward
      ElseIf not IsNull(dtRTL) then
      Calcdate = dtRTL
      ElseIf not IsNull(dtEstm) then
      If Cost < A then
      Calcdate = DateAdd("ww",6, dtEstm)
      ElseIf Cost < B then
      Calcdate = DateAdd("ww",7, dtEstm)
      Else
      Calcdate = DateAdd("ww",8, dtEstm)
      Else
      Calcdate = "No Date Available"
      end function





      --
      Bob Quintal

      PA is y I've altered my email address.

      Comment

      Working...