473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access Report keeps repeating last record.

88
I have a form where the user selects values that I use as filters to populate a report for them. The report has VB code behind it so that it can be dynamic to all the different filters that the user selects. For some reason, when the user selects more than one lender (or column when on the report), it populates the report correctly but then repeats the last record over and over. I'm completely lost as to why it is doing this. It worked in the begining fine, but now (probably after I made some change that I can't remember) it is not working correctly.

It is a lot of code so if anyone is interested in looking at it just let me know and I'll post the code.

Thanks
Jun 19 '07 #1
15 2671
MMcCarthy
14,534 Expert Mod 8TB
I have a form where the user selects values that I use as filters to populate a report for them. The report has VB code behind it so that it can be dynamic to all the different filters that the user selects. For some reason, when the user selects more than one lender (or column when on the report), it populates the report correctly but then repeats the last record over and over. I'm completely lost as to why it is doing this. It worked in the begining fine, but now (probably after I made some change that I can't remember) it is not working correctly.

It is a lot of code so if anyone is interested in looking at it just let me know and I'll post the code.

Thanks
You'll need to post the relevant code for anyone to work out what's going on.

Start with the code used to filter the report. Also provide the sql for the query being used as the record source of the report.
Jun 20 '07 #2
fperri
88
You'll need to post the relevant code for anyone to work out what's going on.

Start with the code used to filter the report. Also provide the sql for the query being used as the record source of the report.
For some reason its not letting me post code. Says my message needs to be longer than 20 characters, but its way more than that.
Jun 21 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
For some reason its not letting me post code. Says my message needs to be longer than 20 characters, but its way more than that.
I'm not sure what the problem is. Are you putting tags on your code?
Jun 21 '07 #4
fperri
88
Yes, I tried it with and without the code tags. Do you think it has something to do with copying and pasting the code into the window?
Jun 21 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Yes, I tried it with and without the code tags. Do you think it has something to do with copying and pasting the code into the window?
At a guess I would say yes. Try pasting it to notepad first.
Jun 21 '07 #6
fperri
88
At a guess I would say yes. Try pasting it to notepad first.
The user selects different filters for the report then clicks a button to generate the report. This is the code that grabs the data based on their selections, then looks in tables that have adjustments and applieds the adjustments.

Expand|Select|Wrap|Line Numbers
  1.  'CLEAR OUT TEMPORARY TABLE
  2. sqlTxt = "DELETE tmpRates.* FROM tmpRates"
  3. DoCmd.RunSQL sqlTxt
  4.  
  5. 'POPULATE TEMPORARY TABLE WITH BASE RATES FOR LENDERS AND LOAN NAME SELECTED
  6. sqlTxt = "INSERT INTO tmpRATES ( LENDER, CHANNEL, MARGIN, HGI, [LOAN NAME], RATE, PRICING )" & _
  7.         " SELECT RATES.LENDER, RATES.CHANNEL, RATES.MARGIN, RATES.HGI, RATES.[LOAN NAME], RATES.RATE, RATES.PRICING" & _
  8.         " FROM RATES" & _
  9.         " WHERE (((RATES.[LOAN NAME])= '" & loanSelected & "') AND ("
  10.  
  11. For i = 0 To lendersCounter1 - 1
  12.     If lendersCounter3 > 1 Then
  13.         If i < 1 Then
  14.         sqlTxt = sqlTxt + " ((RATES.LENDER)= '" & lendersSelected(lendersCounter2 - 1) & "')"
  15.         Else
  16.         sqlTxt = sqlTxt + " OR ((RATES.LENDER) = '" & lendersSelected(lendersCounter2 - 1) & "')"
  17.         End If
  18.     Else
  19.         sqlTxt = sqlTxt + " ((RATES.LENDER) = '" & lendersSelected(lendersCounter2 - 1) & "')"
  20.     End If
  21.     lendersCounter2 = lendersCounter2 - 1
  22. Next i
  23.  
  24. sqlTxt = sqlTxt + ") AND (RATES.RATE > " & minRate & ")"
  25. sqlTxt = sqlTxt + " AND (RATES.RATE < " & maxRate
  26.  
  27. sqlTxt = sqlTxt + "));"
  28.  
  29. 'MsgBox sqlTxt
  30.  
  31. DoCmd.RunSQL sqlTxt
  32. Set recSet = CurrentDb.OpenRecordset("tmpRates")
  33. If recSet.EOF Then
  34.     MsgBox "The database does not contain any records for the criteria provided.", vbOKOnly, "No Records Found."
  35.     recSet.Close
  36.     Exit Sub
  37. End If
  38. '*****************************'
  39. '   APPLY (C)LTV ADJUSTMENTS  '
  40. '*****************************'
  41. 'CLEAR OUT ADJUSTMENT TABLE
  42. sqlTxt = "DELETE tmpAdjustments.* FROM tmpAdjustments"
  43. DoCmd.RunSQL sqlTxt
  44.  
  45. 'IF CLTV ENTERED USE THIS CODE
  46.     If cltvFlag = True Then
  47.       sqlTxt = "INSERT INTO tmpAdjustments ( Lender, [LOAN NAME], FEE_ADJ, RATE_ADJ, [MIN FICO], [MAX FICO], MIN_LTV, MAX_LTV, MIN_CLTV, MAX_CLTV)" & _
  48.                 " SELECT [COMPLETE CLTV].Lender, [COMPLETE CLTV].[LOAN NAME], [COMPLETE CLTV].FEE_ADJ, [COMPLETE CLTV].RATE_ADJ, [COMPLETE CLTV].[MIN FICO], [COMPLETE CLTV].[MAX FICO], [COMPLETE CLTV].MIN_LTV, [COMPLETE CLTV].MAX_LTV, [COMPLETE CLTV].MIN_CLTV, [COMPLETE CLTV].MAX_CLTV" & _
  49.                 " FROM [COMPLETE CLTV] INNER JOIN tmpRATES ON (tmpRATES.[LOAN NAME] = [COMPLETE CLTV].[LOAN NAME]) AND ([COMPLETE CLTV].Lender = tmpRATES.LENDER)" & _
  50.                 " WHERE ((([COMPLETE CLTV].MIN_CLTV) <= " & cLTV
  51.                 sqlTxt = sqlTxt + ") And (([COMPLETE CLTV].MAX_CLTV) >= " & cLTV
  52.                 sqlTxt = sqlTxt + ") And (([COMPLETE CLTV].MIN_LTV) <= " & ltvAmt
  53.                 sqlTxt = sqlTxt + ") And (([COMPLETE CLTV].MAX_LTV) >= " & ltvAmt
  54.                 sqlTxt = sqlTxt + ") And (([COMPLETE CLTV].[MIN FICO]) <= " & ficoScore
  55.                 sqlTxt = sqlTxt + ") And (([COMPLETE CLTV].[MAX FICO]) >= " & ficoScore
  56.                 sqlTxt = sqlTxt + ")) GROUP BY [COMPLETE CLTV].Lender, [COMPLETE CLTV].[LOAN NAME], [COMPLETE CLTV].FEE_ADJ, [COMPLETE CLTV].RATE_ADJ, [COMPLETE CLTV].[MIN FICO], [COMPLETE CLTV].[MAX FICO], [COMPLETE CLTV].MIN_LTV, [COMPLETE CLTV].MAX_LTV, [COMPLETE CLTV].MIN_CLTV, [COMPLETE CLTV].MAX_CLTV;"
  57.         'MsgBox sqlTxt
  58.         DoCmd.RunSQL sqlTxt
  59. End If
  60.  
  61.     Set adjustmentRecordSet = CurrentDb.OpenRecordset("tmpAdjustments")
  62.  
  63. If there were no (C)LTV adjustment retrieved then mark the LTV adjustment Fields in the tmpRates table to zero.
  64.     If adjustmentRecordSet.EOF Then
  65.         recSet.MoveFirst
  66.             Do Until recSet.EOF
  67.                 With recSet
  68.                         recSet.Edit
  69.                         recSet.Fields("LTV_Adjustment_Fee").Value = 0
  70.                         recSet.Fields("LTV_Adjustment_Rate").Value = 0
  71.                         recSet.Fields("LTV").Value = ltvAmt
  72.                         recSet.Fields("CLTV").Value = cLTV
  73.                         recSet.Update
  74.                 End With
  75.                 recSet.MoveNext
  76.             Loop
  77.     'If there were (C)LTV adjustment retrieved then updated the values in the tmpRates table
  78.     Else
  79.         recSet.MoveFirst
  80.         adjustmentRecordSet.MoveFirst
  81.         Do Until adjustmentRecordSet.EOF
  82.             Do Until recSet.EOF
  83.                 If recSet.Fields("LENDER").Value = adjustmentRecordSet.Fields("LENDER").Value Then
  84.                 With recSet
  85.                     recSet.Edit
  86.                     recSet.Fields("LTV_Adjustment_Fee").Value = recSet.Fields("LTV_Adjustment_Fee").Value + adjustmentRecordSet.Fields("FEE_ADJ").Value
  87.                     recSet.Fields("LTV_Adjustment_Rate").Value = recSet.Fields("LTV_Adjustment_Rate").Value + adjustmentRecordSet.Fields("RATE_ADJ").Value
  88.                     recSet.Fields("LTV").Value = ltvAmt
  89.                     recSet.Fields("CLTV").Value = cLTV
  90.                     recSet.Update
  91.                 End With
  92.                 End If
  93.                 recSet.MoveNext
  94.             Loop
  95.             adjustmentRecordSet.MoveNext
  96.             recSet.MoveFirst
  97.         Loop
  98.     End If
  99.  
  100.     adjustmentRecordSet.Close
  101. '***************************'
  102. '   APPLY FICO ADJUSTMENTS  '
  103. '***************************'
  104.  
  105.     'CLEAR OUT ADJUSTMENT TABLE
  106.     sqlTxt = "DELETE tmpAdjustments.* FROM tmpAdjustments"
  107.     DoCmd.RunSQL sqlTxt
  108.  
  109.     'GET ADJUSTMENTS FROM COMPLETE FICO TABLE
  110.  
  111.     If cltvFlag = False Then
  112.  
  113.     sqlTxt = "INSERT INTO tmpAdjustments ( LENDER, [LOAN NAME], [MIN FICO], [MAX FICO], MIN_LTV, MAX_LTV, FEE_ADJ, RATE_ADJ )" & _
  114.             " SELECT [COMPLETE FICO].Lender, [COMPLETE FICO].[LOAN NAME], [COMPLETE FICO].MIN_FICO, [COMPLETE FICO].MAX_FICO, [COMPLETE FICO].MIN_LTV, [COMPLETE FICO].MAX_LTV, [COMPLETE FICO].FEE_ADJ, [COMPLETE FICO].RATE_ADJ" & _
  115.             " FROM tmpRATES INNER JOIN [COMPLETE FICO] ON (tmpRATES.LENDER = [COMPLETE FICO].Lender) AND (tmpRATES.[LOAN NAME] = [COMPLETE FICO].[LOAN NAME])" & _
  116.             " GROUP BY [COMPLETE FICO].Lender, [COMPLETE FICO].[LOAN NAME], [COMPLETE FICO].MIN_FICO, [COMPLETE FICO].MAX_FICO, [COMPLETE FICO].MIN_LTV, [COMPLETE FICO].MAX_LTV, [COMPLETE FICO].FEE_ADJ, [COMPLETE FICO].RATE_ADJ" & _
  117.             " HAVING ((([COMPLETE FICO].MIN_FICO)<= " & ficoScore
  118.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MAX_FICO)>= " & ficoScore
  119.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MIN_LTV)<= " & ltvAmt
  120.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MAX_LTV)>= " & ltvAmt
  121.             sqlTxt = sqlTxt + "));"
  122.     DoCmd.RunSQL sqlTxt
  123.  
  124.     End If
  125.  
  126.     If cltvFlag = True Then
  127.  
  128.     sqlTxt = "INSERT INTO tmpAdjustments ( LENDER, [LOAN NAME], [MIN FICO], [MAX FICO], MIN_LTV, MAX_LTV, FEE_ADJ, RATE_ADJ )" & _
  129.             " SELECT [COMPLETE FICO].Lender, [COMPLETE FICO].[LOAN NAME], [COMPLETE FICO].MIN_FICO, [COMPLETE FICO].MAX_FICO, [COMPLETE FICO].MIN_LTV, [COMPLETE FICO].MAX_LTV, [COMPLETE FICO].FEE_ADJ, [COMPLETE FICO].RATE_ADJ" & _
  130.             " FROM tmpRATES INNER JOIN [COMPLETE FICO] ON (tmpRATES.LENDER = [COMPLETE FICO].Lender) AND (tmpRATES.[LOAN NAME] = [COMPLETE FICO].[LOAN NAME])" & _
  131.             " GROUP BY [COMPLETE FICO].Lender, [COMPLETE FICO].[LOAN NAME], [COMPLETE FICO].MIN_FICO, [COMPLETE FICO].MAX_FICO, [COMPLETE FICO].MIN_LTV, [COMPLETE FICO].MAX_LTV, [COMPLETE FICO].FEE_ADJ, [COMPLETE FICO].RATE_ADJ" & _
  132.             " HAVING ((([COMPLETE FICO].MIN_FICO)<= " & ficoScore
  133.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MAX_FICO)>= " & ficoScore
  134.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MIN_LTV)<= " & cLTV
  135.             sqlTxt = sqlTxt + ") AND (([COMPLETE FICO].MAX_LTV)>= " & cLTV
  136.             sqlTxt = sqlTxt + "));"
  137.     DoCmd.RunSQL sqlTxt
  138.  
  139.     End If
  140.  
  141.     Set adjustmentRecordSet = CurrentDb.OpenRecordset("tmpAdjustments")
  142.  
  143.     'ADD ADJUSTMENTS TO tmpRATES TABLE
  144.     If adjustmentRecordSet.EOF Then
  145.         recSet.MoveFirst
  146.             Do Until recSet.EOF
  147.                 With recSet
  148.                 recSet.Edit
  149.                     recSet.Fields("FICO_Adjustment_Fee").Value = 0
  150.                     recSet.Fields("FICO_Adjustment_Rate").Value = 0
  151.                     recSet.Fields("FICO").Value = ficoScore
  152.                     recSet.Update
  153.                 End With
  154.                 recSet.MoveNext
  155.             Loop
  156.     Else
  157.         recSet.MoveFirst
  158.         adjustmentRecordSet.MoveFirst
  159.         Do Until adjustmentRecordSet.EOF
  160.             Do Until recSet.EOF
  161.                 If recSet.Fields("LENDER").Value = adjustmentRecordSet.Fields("LENDER").Value Then
  162.                 With recSet
  163.                     recSet.Edit
  164.                     recSet.Fields("FICO_Adjustment_Fee").Value = recSet.Fields("FICO_Adjustment_Fee").Value + adjustmentRecordSet.Fields("FEE_ADJ").Value
  165.                     recSet.Fields("FICO_Adjustment_Rate").Value = recSet.Fields("FICO_Adjustment_Rate").Value + adjustmentRecordSet.Fields("RATE_ADJ").Value
  166.                     recSet.Fields("FICO").Value = ficoScore
  167.                     recSet.Update
  168.                 End With
  169.                 End If
  170.                 recSet.MoveNext
  171.             Loop
  172.             adjustmentRecordSet.MoveNext
  173.             recSet.MoveFirst
  174.         Loop
  175.     End If
  176.  
  177.     adjustmentRecordSet.Close
  178.  
  179.  
  180.  
  181. 'CONTINUES THE SAME FOR FOUR MORE ADJUSTMENT TABLES THEN ENDS WITH
  182.  
  183.  
  184.     adjustmentRecordSet.Close
  185.  
  186.     recSet.Close
  187.  
  188.     sqlTxt = "DELETE tmpRATES.LENDER, tmpRATES.CHANNEL, tmpRATES.[LOAN NAME], tmpRATES.DOC_TYPE, tmpRATES.PROP_TYPE, tmpRATES.PURPOSE, tmpRATES.LOAN_AMT, tmpRATES.OCC, tmpRATES.LTV, tmpRATES.FICO, tmpRATES.HGI, tmpRATES.MARGIN, tmpRATES.RATE, tmpRATES.PRICING, tmpRATES.PRICING, tmpRATES.LTV_Adjustment_Rate, tmpRATES.LTV_Adjustment_Fee, tmpRATES.FICO_Adjustment_Rate, tmpRATES.FICO_Adjustment_Fee, tmpRATES.DocType_Adjustment_Rate, tmpRATES.DocType_Adjustment_Fee, tmpRATES.PropType_Adjustment_Rate, tmpRATES.PropType_Adjustment_Fee, tmpRATES.Purpose_Adjustment_Rate, tmpRATES.Purpose_Adjustment_Fee, tmpRATES.OCC_Adjustment_Rate, tmpRATES.OCC_Adjustment_Fee, tmpRATES.OCC_Adjustment_Fee, tmpRATES.LoanAmt_Adjustment_Rate, tmpRATES.LoanAmt_Adjustment_Fee" & _
  189.             " FROM tmpRATES" & _
  190.             " WHERE (((tmpRATES.RATE)=0)) OR (((tmpRATES.RATE) Is Null));"
  191.     DoCmd.RunSQL sqlTxt
  192.  
  193.     Me.Visible = False
  194.  
  195.     DoCmd.OpenReport ("Expanded Criteria Pricing Comparison"), acViewPreview, , , acWindowNormal
  196.  
So that's the code on the form that does the meaty stuff. In the database there is a pivot query that uses the tmpRates table populated in this code. The report uses this pivot query to pull the data. I'll post the code for the report next.

I'm sure there was probably a shorter way to go about this but I'm a newbie so I just tried to do what I knew how to - to get it to work.....so please be nice :)
Jun 22 '07 #7
fperri
88
I'm removing this message because the code showed up alll screwy.
Jun 22 '07 #8
fperri
88
Here is the code on the report.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  '  Constant for maximum number of columns 
  3.    Const conTotalColumns = 14
  4.  
  5.    '  Variables for Database object and Recordset.
  6.    Dim dbsReport As DAO.Database
  7.    Dim rstReport As DAO.Recordset
  8.  
  9.    '  Variables for number of columns and row and report totals.
  10.    Dim intColumnCount As Integer
  11.    Dim columnRank(1 To conTotalColumns - 1) As Double
  12.    Dim columnName(1 To conTotalColumns - 1) As String
  13.    Dim columnValue() As Double
  14.    Dim tmpColumnValue(1 To conTotalColumns - 1) As Double
  15.    Dim valueCounter1 As Integer
  16.    Dim valueCounter2 As Integer
  17.    Dim Holder As Double
  18.    Dim rankRate As Double
  19.    Dim rateCounter As Integer
  20.    Dim oddEven As String
  21.    Dim tmp As Integer
  22.    Dim minVal As Double
  23.    Dim maxVal As Double
  24.    Dim medVal As Double
  25.    Dim counter As Integer
  26.    Dim a As Integer
  27.    Dim processedFlag As Boolean
  28.    Dim holderOne As Double
  29.    Dim holderTwo As Double
  30.    Dim columnCount As Integer
  31.    Dim J As Integer
  32.    Dim X As Integer
  33.    Dim K As Integer
  34.  
  35. Private Function xtabCnulls(varX As Variant)
  36.  
  37.    ' Test if a value is null.
  38.    If IsNull(varX) Then
  39.       ' If varX is null, set varX to 0.
  40.       xtabCnulls = 0
  41.    Else
  42.       ' Otherwise, return varX.
  43.       xtabCnulls = varX
  44.    End If
  45.  
  46. End Function
  47.  
  48.  
  49.  
  50.  
  51. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  52.  
  53.    minVal = 0
  54.    maxVal = 0
  55.    medVal = 0
  56.  
  57.    Dim intX As Integer
  58.    '  Verify that you are not at end of recordset.
  59.    If Not rstReport.EOF Then
  60.       '  If FormatCount is 1, put values from recordset into text boxes
  61.       '  in "Detail" section.
  62.       If Me.FormatCount = 1 Then
  63.          K = 1
  64.          For intX = 1 To intColumnCount
  65.  
  66.             Me("Col" + Format(intX)) = xtabCnulls(rstReport(intX - 1))
  67.  
  68.             'Get Minimum value
  69.             If intX > 1 Then
  70.                 If xtabCnulls(rstReport(intX - 1)) = 0 Then
  71.                     minVal = minVal
  72.                 Else
  73.                     If intX = 2 Then
  74.                         minVal = xtabCnulls(rstReport(intX - 1))
  75.                     Else
  76.                         If minVal < xtabCnulls(rstReport(intX - 1)) Then
  77.                             minVal = minVal
  78.                         Else
  79.                             minVal = xtabCnulls(rstReport(intX - 1))
  80.                         End If
  81.                     End If
  82.                 End If
  83.             End If
  84.  
  85.             'Get Maximum Value
  86.             If intX > 1 Then
  87.                 If xtabCnulls(rstReport(intX - 1)) = 0 Then
  88.                     maxVal = maxVal
  89.                 Else
  90.                     If intX = 2 Then
  91.                         maxVal = xtabCnulls(rstReport(intX - 1))
  92.                     Else
  93.                         If maxVal = 0 Then
  94.                             maxVal = xtabCnulls(rstReport(intX - 1))
  95.                         Else
  96.                             If maxVal > xtabCnulls(rstReport(intX - 1)) Then
  97.                                 maxVal = maxVal
  98.                             Else
  99.                                 maxVal = xtabCnulls(rstReport(intX - 1))
  100.                             End If
  101.                         End If
  102.                     End If
  103.                 End If
  104.             End If
  105.  
  106.             'Get Median
  107.             If intX > 1 And xtabCnulls(rstReport(intX - 1)) <> 0 Then
  108.                 counter = counter + 1
  109.                 medVal = medVal + xtabCnulls(rstReport(intX - 1))
  110.             End If
  111.  
  112.             If intX > 1 Then
  113.                 If Me("Col1") = rankRate Then
  114.                         Holder = xtabCnulls(rstReport(intX - 1))
  115.                         If Holder = 0 Then
  116.                             'Do nothing
  117.                         Else
  118.                             columnName(intX) = "Col" & (intX)
  119.                             columnRank(intX) = xtabCnulls(rstReport(intX - 1))
  120.                             tmpColumnValue(K) = xtabCnulls(rstReport(intX - 1))
  121.                             valueCounter1 = valueCounter1 + 1
  122.                             K = K + 1
  123.                         End If
  124.                 End If
  125.             End If
  126.         Next intX
  127.  
  128.  
  129.          '  Hide unused text boxes in the "Detail" section.
  130.          For intX = intColumnCount + 4 To conTotalColumns
  131.             Me("Col" + Format(intX)).Visible = False
  132.          Next intX
  133.  
  134.  
  135.          'Check for middle rate to highlight
  136.          If Me("Col1") = rankRate Then
  137.             'Highlight the row
  138.             Me("Line49").Visible = True
  139.             Me("Line50").Visible = True
  140.             processedFlag = True
  141.          Else
  142.             Me("Line49").Visible = False
  143.             Me("Line50").Visible = False
  144.             processedFlag = False
  145.          End If
  146.  
  147.          '  Move to next record in recordset.
  148.          rstReport.MoveNext
  149.       End If
  150.    End If
  151.  
  152.  
  153.  
  154. 'Grabbing Values for rank
  155. If processedFlag = True Then
  156.  
  157.     ReDim columnValue(valueCounter1 - 1)
  158.  
  159.  
  160.     a = 0
  161.  
  162. ' Grabbing values for rank
  163.     For i = 1 To valueCounter1
  164.         If tmpColumnValue(i) <> 0 Then
  165.             columnValue(a) = tmpColumnValue(i)
  166.             valueCounter2 = valueCounter2 + 1
  167.             a = a + 1
  168.         End If
  169.     Next i
  170. ' Putting values in order of rank - from the end of the array to the begining of the array
  171.     For X = 1 To 10
  172.         For J = valueCounter1 - 1 To 1 Step -1
  173.             If J <> 0 Then
  174.                 If columnValue(J) < columnValue(J - 1) Then
  175.                     holderOne = columnValue(J)
  176.                     holderTwo = columnValue(J - 1)
  177.                     columnValue(J) = holderTwo
  178.                     columnValue(J - 1) = holderOne
  179.                 End If
  180.             End If
  181.         Next J
  182.     Next X
  183. ' Putting values in order of rank = from the begining of the array to the end of the array
  184.    For X = 1 To 10
  185.         For J = 0 To valueCounter1 - 1
  186.             If J = valueCounter1 - 1 Then
  187.                 'Do Nothing
  188.  
  189.             Else
  190.                 If columnValue(J) > columnValue(J + 1) Then
  191.                     holderOne = columnValue(J)
  192.                     holderTwo = columnValue(J + 1)
  193.                     columnValue(J) = holderTwo
  194.                     columnValue(J + 1) = holderOne
  195.                 End If
  196.             End If
  197.         Next J
  198.    Next X
  199. End If
  200. End Sub
  201.  
  202.  
  203.  
  204. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  205.  
  206.    Dim intX As Integer
  207.    Dim lngRowTotal As Long
  208.  
  209.    '  If PrintCount is 1, initialize rowTotal variable.
  210.    '  Add to column totals.
  211.    If Me.PrintCount = 1 Then
  212.       ' Compute Median
  213.          If medVal = maxVal And medVal = minVal Then
  214.             medVal = medVal
  215.          Else
  216.             medVal = medVal / counter
  217.          End If
  218.  
  219.          ' Put Min, Max & Median Values into Fields
  220.          Me("Col" + Format(intColumnCount + 1)) = maxVal
  221.          Me("Col" + Format(intColumnCount + 1)).Visible = True
  222.          Me("Col" + Format(intColumnCount + 2)) = minVal
  223.          Me("Col" + Format(intColumnCount + 2)).Visible = True
  224.          Me("Col" + Format(intColumnCount + 3)) = medVal
  225.          Me("Col" + Format(intColumnCount + 3)).Visible = True
  226.  
  227.  
  228.  
  229.          maxVal = 0
  230.          minVal = 0
  231.          medVal = 0
  232.    End If
  233. End Sub
  234.  
  235.  
  236.  
  237. Private Sub Detail_Retreat()
  238.  
  239.    ' Always back up to previous record when "Detail" section retreats.
  240.    rstReport.MovePrevious
  241.  
  242. End Sub
  243.  
  244.  
  245. Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
  246.  
  247.    Dim intX As Integer
  248.  
  249.    '  Put column headings into text boxes in page header.
  250.    For intX = 1 To intColumnCount
  251.       Me("Head" + Format(intX)) = rstReport(intX - 1).Name
  252.    Next intX
  253.  
  254.    '  Make next available text boxes min, max & Median
  255.    'Me("Head" + Format(intColumnCount + 1)) = "Totals"
  256.    Me("Head" + Format(intColumnCount + 1)) = "Highest"
  257.    Me("Head" + Format(intColumnCount + 1)).Visible = True
  258.    Me("Head" + Format(intColumnCount + 2)) = "Lowest"
  259.    Me("Head" + Format(intColumnCount + 2)).Visible = True
  260.    Me("Head" + Format(intColumnCount + 3)) = "Median"
  261.    Me("Head" + Format(intColumnCount + 3)).Visible = True
  262.  
  263.    '  Hide unused text boxes in page header.
  264.    For intX = (intColumnCount + 4) To conTotalColumns
  265.       Me("Head" + Format(intX)).Visible = False
  266.    Next intX
  267.  
  268. End Sub
  269.  
  270.  
  271. Private Sub Report_Close()
  272.  
  273.    On Error Resume Next
  274.  
  275.    '  Close recordset.
  276.    rstReport.Close
  277.    'DoCmd.openForm ("Comp_Report")
  278.    [Forms]![Comp_Report].[Visible] = True
  279.    My.Form.Comp_Report.Visible = True
  280.  
  281. End Sub
  282.  
  283.  
  284. Private Sub Report_NoData(Cancel As Integer)
  285.  
  286.    MsgBox "No records match the criteria you entered.", vbExclamation, "No Records Found"
  287.    rstReport.Close
  288.    Cancel = True
  289.  
  290. End Sub
  291.  
  292.  
  293. Private Sub Report_Open(Cancel As Integer)
  294.  
  295.    '  Create underlying recordset for report using pivotRatesOnly Query
  296.  
  297.    Dim intX As Integer
  298.    Dim qdf As QueryDef
  299.    Dim frm As Form
  300.  
  301.    '  Set database variable to current database.
  302.    Set dbsReport = CurrentDb
  303.    'Set frm = Forms!EmployeeSalesDialogBox
  304.    '  Open QueryDef object.
  305.    Set qdf = dbsReport.QueryDefs("pivotRatesOnly")
  306.  
  307.    '  Open Recordset object.
  308.    Set rstReport = qdf.OpenRecordset()
  309.  
  310.    '  Set a variable to hold number of columns in crosstab query.
  311.    intColumnCount = rstReport.Fields.Count
  312.  
  313.    If Not rstReport.EOF Then
  314.            ' Get number of rates selected
  315.    Do Until rstReport.EOF
  316.         rateCounter = rateCounter + 1
  317.         rstReport.MoveNext
  318.    Loop
  319.  
  320.    rstReport.MoveFirst
  321.  
  322.    ' Find out if the number is odd or even
  323.    If num Mod rateCounter = 0 Then
  324.         oddEven = "Even"
  325.    Else
  326.         oddEven = "Odd"
  327.    End If
  328.  
  329.    ' If it is an even count -
  330.    If oddEven = "Even" Then
  331.         'Divide rateCounter by two
  332.         rateCounter = rateCounter / 2
  333.             'Loop to that number
  334.             For i = 0 To rateCounter
  335.                 ' Once we are at that number
  336.                 If i = rateCounter Then
  337.                     ' Tak that rate - The 1st middle value
  338.                     rankRate = rstReport.Fields("RATE").Value
  339.                     'MsgBox rankRate
  340.                 Else
  341.                     rstReport.MoveNext
  342.                 End If
  343.             Next i
  344.     End If
  345.  
  346.     ' If it is an odd count -
  347.     If oddEven = "Odd" Then
  348.         'Divide rateCounter by two
  349.         rateCounter = rateCounter / 2
  350.         'Strip what is after the decimal point and round to the next number
  351.         tmp = Val(rateCounter)
  352.             If rateCounter - tmp >= 0.5 Then
  353.                 rateCounter = tmp + 1
  354.             Else
  355.                 rateCounter = tmp
  356.             End If
  357.         'Loop to that number
  358.             For i = 0 To rateCounter
  359.                 ' Once we are at that number
  360.                 If i = rateCounter Then
  361.                     ' Tak that rate - The 1st middle value
  362.                     rankRate = rstReport.Fields("RATE").Value
  363.                     MsgBox rankRate
  364.                 Else
  365.                     rstReport.MoveNext
  366.                 End If
  367.             Next i
  368.     End If
  369.  
  370. rstReport.MoveFirst
  371. End If    
  372. End Sub
  373.  
Jun 22 '07 #9
LacrosseB0ss
113 100+
does the code repeat the last record an infinite number of times? I.E. Do you need to hit "CTRL + BREAK" to make it stop? Or is there a fixed amount of times?

If it's infinite, check your looping end conditions. If it's fixed, you will need some deeper digging.

Hope this helps
- LB
Jun 22 '07 #10
fperri
88
Here is the rest......

Expand|Select|Wrap|Line Numbers
  1. Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
  2.  
  3.    Dim intX As Integer
  4.    Dim X As Integer
  5.  
  6.    '  Put rank value in text boxes in report footer.
  7.    '  Start at column 2 (first text box with crosstab value).
  8.  
  9.  
  10.         For X = 0 To valueCounter1 - 1
  11.             For i = 1 To 10
  12.                 If columnRank(i) = columnValue(X) Then
  13.                     Me("Tot" + Format(i)) = X + 1
  14.                 End If
  15.             Next i
  16.         Next X
  17.  
  18.    '  Hide unused text boxes in report footer.
  19.    For intX = intColumnCount + 2 To conTotalColumns
  20.     '  Me("Tot" + Format(intX)).Visible = False
  21.    Next intX
  22.  
  23. End Sub
  24.  
  25.  
  26. Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
  27.  
  28.    '  Move to first record in recordset at the beginning of the report
  29.    '  or when the report is restarted. (A report is restarted when
  30.    '  you print a report from Print Preview window, or when you return
  31.    '  to a previous page while previewing.)
  32.    rstReport.MoveFirst
  33.  
  34.    'Initialize variables.
  35.    InitVars
  36.  
  37. End Sub
It all works, cept its repeating the last record in the report over and over giving me and extra page of the same values throughout. I ran the report a bunch of times to try and see if there was a link between how many times it was repeated but I couldn't find anything. But I did notice when stepping throught the code that after it gets to the end of the recordset it keeps going through the process. I think that this is where the repeated records are coming from but I can't figure out what code to change or add to get it to stop.
Jun 22 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Look at the placement of the MoveNext in your Report Open procedure. Follow the logic and see if the recordset will move under those conditions.
Jun 22 '07 #12
fperri
88
Look at the placement of the MoveNext in your Report Open procedure. Follow the logic and see if the recordset will move under those conditions.
There is no MoveNext in the Report Open procedure. There is a move next in the detail format through.

I just stepped through the code again (Line by line) as it was pulling up the report. It goes throught the recordset fine, but when it reaches the end of the recordset it keeps going back and forth between the detail_format and detail_print procedures without doing anything - I mean, without processing any of the code because it is the end of the recordset - so, it just pops back and forth until finally it stops for some unknow reason to me - so the final recordset record is getting repeated.

I'm wondering if it has anything to do with the formatCount and printCount variables? The code is written to execute when the printCount or formatCount is 1, but only access can change this value. I can't figure out what triggers the code to finally stop but I'm guessing it stops when one of these gets changed to zero, but I can't change the value because it is a read only.

So, I added a boolean flag that I change to true if it is the end of the recordset and put an if statment arount the code in the detailPrint procedure for it to only run if the flag is false otherwise exit the sub. It worked the very first time I ran it after adding the code and it didn't repeat any records. I was sooooooo jacked.......thought I had fixed it.....but the next time I ran it it started repeating records again. It makes absolutely no sense to me.
Jun 28 '07 #13
MMcCarthy
14,534 Expert Mod 8TB
There is no MoveNext in the Report Open procedure. There is a move next in the detail format through.
Actually there are a few of them. These are the ones I was talking about though.

Expand|Select|Wrap|Line Numbers
  1. ' If it is an even count -
  2. If oddEven = "Even" Then
  3.    'Divide rateCounter by two
  4.    rateCounter = rateCounter / 2
  5.    'Loop to that number
  6.    For i = 0 To rateCounter
  7.       ' Once we are at that number
  8.       If i = rateCounter Then
  9.          ' Tak that rate - The 1st middle value
  10.          rankRate = rstReport.Fields("RATE").Value
  11.          'MsgBox rankRate
  12.       Else
  13.          rstReport.MoveNext
  14.       End If
  15.    Next i
  16. End If
  17.  
  18. ' If it is an odd count -
  19. If oddEven = "Odd" Then
  20.     'Divide rateCounter by two
  21.     rateCounter = rateCounter / 2
  22.     'Strip what is after the decimal point and round to the next number
  23.     tmp = Val(rateCounter)
  24.         If rateCounter - tmp >= 0.5 Then
  25.             rateCounter = tmp + 1
  26.         Else
  27.             rateCounter = tmp
  28.         End If
  29.     'Loop to that number
  30.     For i = 0 To rateCounter
  31.         ' Once we are at that number
  32.         If i = rateCounter Then
  33.             ' Tak that rate - The 1st middle value
  34.             rankRate = rstReport.Fields("RATE").Value
  35.             MsgBox rankRate
  36.         Else
  37.             rstReport.MoveNext
  38.         End If
  39.     Next i
  40. End If
  41.  
Jun 28 '07 #14
fperri
88
Actually there are a few of them. These are the ones I was talking about though.

Expand|Select|Wrap|Line Numbers
  1. ' If it is an even count -
  2. If oddEven = "Even" Then
  3.    'Divide rateCounter by two
  4.    rateCounter = rateCounter / 2
  5.    'Loop to that number
  6.    For i = 0 To rateCounter
  7.       ' Once we are at that number
  8.       If i = rateCounter Then
  9.          ' Tak that rate - The 1st middle value
  10.          rankRate = rstReport.Fields("RATE").Value
  11.          'MsgBox rankRate
  12.       Else
  13.          rstReport.MoveNext
  14.       End If
  15.    Next i
  16. End If
  17.  
  18. ' If it is an odd count -
  19. If oddEven = "Odd" Then
  20.     'Divide rateCounter by two
  21.     rateCounter = rateCounter / 2
  22.     'Strip what is after the decimal point and round to the next number
  23.     tmp = Val(rateCounter)
  24.         If rateCounter - tmp >= 0.5 Then
  25.             rateCounter = tmp + 1
  26.         Else
  27.             rateCounter = tmp
  28.         End If
  29.     'Loop to that number
  30.     For i = 0 To rateCounter
  31.         ' Once we are at that number
  32.         If i = rateCounter Then
  33.             ' Tak that rate - The 1st middle value
  34.             rankRate = rstReport.Fields("RATE").Value
  35.             MsgBox rankRate
  36.         Else
  37.             rstReport.MoveNext
  38.         End If
  39.     Next i
  40. End If
  41.  

I actually figured it out........I'm a retard. Seriously, I am. What it ended up being was that the report is pulling its data from a crosstab query. The table that the crosstab table is using had some of the fields with null and zero values in them - so when the crosstab was created it had repeated rate rows in it because not all the records had the same values in the other fields (the ones that had null or zero values should have had a value in them that the other records all share). So........and I don't completely understand....but I guessing that it was looping through the recordset in the code assigning the values to the fields at the same time - since I assigned the crosstab query to the report's recordsource as well, it was looping through the recordset as well. Somehow, when its looping in the code, it assigns the values properly but reaches the end of the recordset before the report does, that's why it keeps going and repeats the last record assigned until it reaches the end of the recordset.

I figured it out when I finally decided to make a copy of the report, take out the code, and assign the fields to the recordsource and see what came up. Well, the exact same amount of rows - so I opened up the crosstab and saw it.

I feel silly - but thank you though for trying to help me.

~ Franccesca
Jun 28 '07 #15
MMcCarthy
14,534 Expert Mod 8TB
No Problem Franccesca.

I'm glad you got it working.
Jun 28 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: deko | last post by:
I can't move a multi-page report to the last record unless I keep the popup form (that defined it's subreports) open. DoCmd.OpenReport "rptStandard", acViewNormal DoCmd.Close acForm,...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
3
by: Chris | last post by:
Hello all. I have a database that I use to send email updates to people. Everything is working fine, but one suggestion I keep getting is to add a link to the automatic emails that will open up the...
0
by: Jaap | last post by:
Hi, Situation is as follows: - A report has a subreport - The subreport has records of which two will fit on a page - When the complete report is printed, the last record in the subreport...
2
by: Alpha | last post by:
I have a C# program that user would select several search criteria and then outputs to the Crystal Report. A message is output to user if no matching record is found. In my code I also clear,...
2
by: dauwe.peter | last post by:
A table : Nameperson, Book nr, Bookdatein, Bookdateout, CD nr, cddatein, cddateout, dvd nr, dvddatein, dvddateout. I would like a query where a see the personsname en de last book with the...
7
by: baool | last post by:
I have a report that keeps track of sales by company for any given month within a year. I am using two subreports embedded within a report to produce 2006 (one subreport) and 2007 (the other...
4
by: lupo666 | last post by:
Hi everybody, this time I have three problems driving me nuts :-((( (1) I have a report with 20 or so Yes/No "squares". Is there a way to either hide/show the "square" or change the yes/no...
4
by: zufie | last post by:
I have a report that return all the records (materials ordered) by all callers each day. I want the report to just show all the records (materials ordered) by each individual caller each day on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.