'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'Due to the fact that I could not find any examples of age analysis
'anywhere in any books/manuals, I tried to come up with an age 
'analysis myself.

'Here is my first try at doing an age analysis on my Patient Information
'form. I have a table Treatment which contains Fee and PaymentAmount
'with Date. From this I created a query to filter Fees for each period
'(via Date()-DateofFee, <61 and >90, for example), together with a total 
'SumOfFee field and these were then handled in the procedure 
'cmdAgeing_Click listed below

'All the code below should be fairly self explanatory, but if you have
'any comments (OR CRITIQUE OR IMPROVEMENTS) please let me 
'know at my compuserve address. Good Luck

'This is freeware - aren't we all supposed to be helping each other?
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Sub cmdAgeing_Click ()
On Error GoTo cmdAgeing_Err     'TRAP ANY ERRORS

Dim vCurrent As Currency            'DECLARE VARIABLES
Dim v30 As Currency
Dim v60 As Currency
Dim v90 As Currency
Dim v120 As Currency
Dim vPay As Currency
Dim vAns As Currency

'    LET ME EXPLAIN A LITTLE FURTHER HERE: txtCurrent,txt30,etc
'   ARE TEXT BOXES THAT ARE INVISIBLE WITH THEIR DATA 
'   REFERENCED FROM THE QUERY MENTIONED ABOVE

If Me!txtCurrent > 0 Then          'TO REMOVE NULL VALUES   
    vCurrent = Me!txtCurrent
    Else
    vCurrent = 0
End If

If Me!txt30 > 0 Then
    v30 = Me!txt30
    Else
    v30 = 0
End If

If Me!txt60 > 0 Then
    v60 = Me!txt60
    Else
    v60 = 0
End If

If Me!txt90 > 0 Then
    v90 = Me!txt90
    Else
    v90 = 0
End If

If Me!txt120 > 0 Then
    v120 = Me!txt120
    Else
    v120 = 0
End If

If Me!txtPayTotal > 0 Then
    vPay = Me!txtPayTotal
    Else
    vPay = 0
End If



'BEGIN CALCULATIONS: AGAIN A NEW SERIES OF TEXT BOXES
'CALLED NCurrent,N30,etc WERE SET UP. THEIR VALUES ARE 
'CALCULATED FROM THE FOLLOWING:

vAns = v120 - vPay
If v120 = 0 Then
    Me!N120 = ""
 Else
    If vAns > 0 Then
      Me!N120 = vAns
      Me!N90 = v90
      Me!N60 = v60
      Me!N30 = v30
      Me!NCurrent = vCurrent
      Exit Sub
    Else
      Me!N120 = ""
    End If
End If


If v90 = 0 Then
    Me!N90 = ""
Else
    vAns = v90 + vAns
  If vAns > 0 Then
      Me!N90 = vAns
      Me!N60 = v60
      Me!N30 = v30
      Me!NCurrent = vCurrent
      Exit Sub
  Else
    Me!N90 = ""
  End If
End If


If v60 = 0 Then
    Me!N60 = ""
  Else
     vAns = v60 + vAns
    If vAns > 0 Then
      Me!N60 = vAns
      Me!N30 = v30
      Me!NCurrent = vCurrent
      Exit Sub
    Else
      Me!N60 = ""
    End If
End If


If v30 = 0 Then
    Me!N30 = ""
  Else
    vAns = v30 + vAns
    If vAns > 0 Then
      Me!N30 = vAns
      Me!NCurrent = vCurrent
      Exit Sub
    Else
      Me!N30 = ""
    End If
End If



vAns = vCurrent + vAns

    Me!NCurrent = vAns
  



Exit_cmdAgeing_Click:
    Exit Sub

cmdAgeing_Err:
    MsgBox Error$
    Resume Exit_cmdAgeing_Click



    
End Sub

