If Then Statement Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cryptotech2000
    New Member
    • Jun 2007
    • 12

    If Then Statement Help

    What I am looking to do is create an if then statement for a particular access query, here are the facts

    Tables used
    Mainframe Report List

    Fields Within the table that are used for the if then statement
    GENERATIONS
    FREQUENCY
    EXTENDED

    what i would like is to say if FREQUENCY = Daily5 then Divide value in GENERATIONS by 5 and Place the Result in EXTENDED ELSE IF FREQUENCY = WEEKLY then Divide value in GENERATIONS by 1 etc etc for the following values

    Daily5
    Daily7
    Weekly
    Monthly
    Quarterly
    Annualy
    On Demand


    ELSE IF NULL then EXTENDED = NULL
    Any help on this would be greatly appreciated as this has a deadline of tomorrow morning :( Thanks
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by cryptotech2000
    What I am looking to do is create an if then statement for a particular access query, here are the facts

    Tables used
    Mainframe Report List

    Fields Within the table that are used for the if then statement
    GENERATIONS
    FREQUENCY
    EXTENDED

    what i would like is to say if FREQUENCY = Daily5 then Divide value in GENERATIONS by 5 and Place the Result in EXTENDED ELSE IF FREQUENCY = WEEKLY then Divide value in GENERATIONS by 1 etc etc for the following values

    Daily5
    Daily7
    Weekly
    Monthly
    Quarterly
    Annualy
    On Demand


    ELSE IF NULL then EXTENDED = NULL
    Any help on this would be greatly appreciated as this has a deadline of tomorrow morning :( Thanks
    In my opinion, this can only be done in code and I have posted the partial solution and logic below:
    [CODE=VB]Dim MyDB As DAO.Database, MyRS As DAO.Recordset

    Set MyDB = CurrentDb()
    Set MyRS = MyDB.OpenRecord set("Mainframe Report List", dbOpenDynaset)

    MyRS.MoveFirst

    Do While Not MyRS.EOF
    MyRS.Edit
    Select Case MyRS![FREQUENCY]
    Case "Daily5"
    MyRS![EXTENDED] = MyRS![GENERATIONS] / 5
    Case "Weekly"
    'Here is where I get confused...
    Case Else
    MyRS![EXTENDED] = Null
    End Select
    MyRS.Update
    MyRS.MoveNext
    Loop

    MyRS.Close[/CODE]

    This is where I totally got confused. You'll have to fill in the missing code yourself.
    IF FREQUENCY = WEEKLY then Divide value in GENERATIONS by 1 etc etc for the following values

    Daily5
    Daily7
    Weekly
    Monthly
    Quarterly
    Annualy
    On Demand

    Comment

    Working...