Rx_
Nothing In Moderation
- Local time
- Today, 15:54
- Joined
- Oct 22, 2009
- Messages
- 2,803
Used an IIF statement to take care of this. But, it really bothers me.
Can someone suggest a better method? Something more eloquent than an IIF? Using a top 12 in the query with the IIF provides the correct result.
The 2 table fields have Year and Month. Pick a year - Month and select the last 12 months. Using a Month - 1 (e.g. January = 1) creates a problem.
The list box for Months returns a value from 1..12. The year and month were used to generate a 12 month rolling average from Year - Month to Year (Month -1) e.g 2012 June to 2011 July.
When January 2012 hit - the (Month-1) returned a zero. (the application is only three months old so we discovered all January had this problem.
See two attachments. A permit requires samples and later the sample readings populate the record. Once a permit is granted, all of the Samples are created in advance. One reading a month.
The tables were created this way so that auditors could easily understand the process for this fairly new regulation. The auditors in December just loved it. This is mentioned because we know it doesn't meet some of the typical database table design rules.
Sometimes it is the Little Things that really bother me.
Can someone suggest a better method? Something more eloquent than an IIF? Using a top 12 in the query with the IIF provides the correct result.
The 2 table fields have Year and Month. Pick a year - Month and select the last 12 months. Using a Month - 1 (e.g. January = 1) creates a problem.
The list box for Months returns a value from 1..12. The year and month were used to generate a 12 month rolling average from Year - Month to Year (Month -1) e.g 2012 June to 2011 July.
When January 2012 hit - the (Month-1) returned a zero. (the application is only three months old so we discovered all January had this problem.
See two attachments. A permit requires samples and later the sample readings populate the record. Once a permit is granted, all of the Samples are created in advance. One reading a month.
The tables were created this way so that auditors could easily understand the process for this fairly new regulation. The auditors in December just loved it. This is mentioned because we know it doesn't meet some of the typical database table design rules.
Code:
Dim lstED_EMMoFlip As Integer ' We subtract one month, will Jan each year -1 is zero - so fix here - HOW CAN THIS BE IMPROVED?
lstED_EMMoFlip = IIf(Me.lstED_EMMo = 1, 2, Me.lstED_EMMo)
10 On Error Resume Next
20 Me.ID_Well = Me.lst_id_wells
' Ed Emission Tanks top 12 query Use a Combo box to choose Year and Combo Box to choose Month for sqlBetween
30 sqlBetween = "Between #" & Me.lstED_EMMo & "/1/" & Me.lstCalYr & "# AND #" & (lstED_EMMoFlip - 1) & "/1/" & (Me.lstCalYr - 1) & "#"
40 SqlStrTank = "SELECT TOP 12 ED_EMTank.ID_Tank, ED_EMTank.ID_Wells, ED_EMTank.CalYear, ED_EMTank.CalMonth, ED_EMTank.Throughput, ED_EMTank.UnControlled, " & _
"ED_EMTank.[Actual Controlled], ED_EMTank.Controlled, ED_EMTank.Efficiency, DateSerial([CalYear],[mo],1) AS YrMoDay "
50 SqlStrTank = SqlStrTank & "FROM ED_EMTank "
60 SqlStrTank = SqlStrTank & "WHERE (((ED_EMTank.ID_Wells)=" & Me.ID_Well & ") AND ((DateSerial([CalYear],[mo],1))" & sqlBetween & ")) "
70 SqlStrTank = SqlStrTank & " ORDER BY DateSerial([CalYear],[mo],1) DESC"
80 Me.lstED_EM_Tank.RowSource = SqlStrTank
90 CreateTempTable SqlStrTank ' create a temp table of the 12 records That will show up in the Listbox
100 TankTotals ' Run a Totals query on the new Temp table - populate the multiple text boxes
Sometimes it is the Little Things that really bother me.