Valid Point

Here's the code:

VB Code:
  1. Private Sub CompressDay2Month(strSourceTBLName As String, strDestTBLName As String)
  2. 'Compress Selected Symbol to Monthly Data Using Daily Data
  3. 'Note: No Time stamp on Monthly
  4.  
  5.    On Error GoTo Error_CompressDay2Month
  6.  
  7.    Dim rsSource As Recordset
  8.    Dim rsDest As Recordset
  9.    Dim iMonth As Integer, iPrevMonth As Integer
  10.    Dim dtmDate As Date, dtmPrevDate As Date
  11.    Dim sngOpen As Single, sngMnthOpen As Single
  12.    Dim sngHigh As Single, sngMnthHigh As Single
  13.    Dim sngLow As Single, sngMnthLow As Single
  14.    Dim sngClose As Single, sngPrevClose As Single
  15.    
  16.    '*******
  17.    'STARTUP
  18.    '*******
  19.    iPrevMonth = 0
  20.    sngMnthHigh = -999999.99
  21.    sngMnthLow = 999999.99
  22.  
  23.    Set rsSource = DaoDb.OpenRecordset(strSourceTBLName)
  24.    Set rsDest = DaoDb.OpenRecordset(strDestTBLName)
  25.    
  26.    '****
  27.    'MAIN
  28.    '****
  29.    With rsSource
  30.  
  31.       'Get All Daily Records
  32.       Do Until .EOF
  33.      
  34.          'Get a Record
  35.          dtmDate = ExtractDate(!fldHistDateTime)  'CRITICAL Requires DB Format of mm/dd/yyyy
  36.          sngOpen = !fldHistOpen
  37.          sngHigh = !fldHistHigh
  38.          sngLow = !fldHistLow
  39.          sngClose = !fldHistClose
  40.          
  41.          'Get Integer Month
  42.          iMonth = Month(dtmDate)
  43.  
  44.          'For 1st Record Only
  45.          If iPrevMonth = 0 Then
  46.             iPrevMonth = iMonth
  47.             sngMnthOpen = sngOpen
  48.          End If
  49.          
  50.          'Compare Current Record to Prev Record
  51.          If (iMonth > iPrevMonth) Or (iMonth < iPrevMonth) Then
  52.          
  53.             rsDest.AddNew
  54.            
  55.              'Full Month Processed so Put EOM date on
  56.             rsDest!fldHistDateTime = CombineDateTime(EndOfMonth(dtmPrevDate), 0)
  57.             rsDest!fldHistOpen = sngMnthOpen
  58.             rsDest!fldHistHigh = sngMnthHigh
  59.             rsDest!fldHistLow = sngMnthLow
  60.             rsDest!fldHistClose = sngPrevClose
  61.            
  62.             rsDest.Update
  63.            
  64.             '1st rcd of month has been read, so save Open
  65.             sngMnthOpen = sngOpen
  66.             sngMnthHigh = -999999.99
  67.             sngMnthLow = 999999.99
  68.            
  69.          End If
  70.                
  71.          If sngHigh > sngMnthHigh Then sngMnthHigh = sngHigh
  72.          If sngLow < sngMnthLow Then sngMnthLow = sngLow
  73.          
  74.          iPrevMonth = iMonth
  75.          dtmPrevDate = dtmDate
  76.          sngPrevClose = sngClose
  77.          
  78.          .MoveNext
  79.          
  80.          'Get any messages if mouse or keyboard used
  81.          If GetInputState() Then DoEvents
  82.          
  83.       Loop
  84.    End With
  85.      
  86.    'Make Sure Store Last Partial Month in DaoDb
  87.    'NOTE: Record may or may NOT be EOM
  88.    With rsDest
  89.       .AddNew
  90.      
  91.       'Note: No Time on Monthly
  92.       !fldHistDateTime = CombineDateTime(dtmPrevDate, 0)  '<May or May Not be EOM
  93.       !fldHistOpen = sngMnthOpen
  94.       !fldHistHigh = sngMnthHigh
  95.       !fldHistLow = sngMnthLow
  96.       !fldHistClose = sngPrevClose
  97.       .Update
  98.    End With
  99.    
  100.    rsSource.Close
  101.    rsDest.Close
  102.    
  103.    '******
  104.    'WrapUP
  105.    '******
  106.    
  107.    Exit Sub
  108.  
  109. End Sub