Never mind this post. I figured out the problem. I can't believe this. I
passed my dataview by reference into a function that gets the total number of
clients for the state
'Get the total number of records for agencies in a particular state.
dv.RowFilter = product & " = 1 AND state = '" & strState & "'"
nTotal = dv.Count
I filter the dv a second time getting so that I can get the total. Sorry for
the trouble.
--
TC
[quoted text, click to view] "Terrance" wrote:
> I've been having an issue with an application that keeps track of
> applications that a client has by state and print this information from my
> .net app to an excel file. I'm using a dataview to filter and sort the
> records so that I can print all of the Florida client together in column then
> all the North Carolina clients and so forth. So I have 3 columns (state,
> agency, and total) ; in order to prevent the list showing the state each time
> for each client I print the respected state compare it to the next state name
> in the dataview and if it's the same I don't reprint the state just move over
> to the next row and print the client name. Everything works fine except for
> my NC client list. The NC client list is the largest with 59 names and 59
> names print with a correct total but it doesn't print the first 8 which are
> agencies with A and B names and it duplicates the first 8 that was printed if
> that makes since. I've been working on this for ever and can't figure out why
> it's doing what it's doing.The problem is in the WriteToData Sub. The bad
> thing about this is I wrote the Sub but can't figure out what I'm doing
> wrong. Can someone check behind my code and tell me what I'm doing wrong?
>
> Private Sub CreateAppList(ByVal eApp As Application, ByVal ws As Worksheet,
> ByRef dv As DataView)
> 'Cast the worksheet into the appWorkSheet object
> Dim appWorkSheet As Worksheet = DirectCast(eApp.Worksheets("APP"),
> Excel.Worksheet)
> Try
> appWorkSheet.Activate() 'Activate the worksheet
>
> 'Cast the current worksheet into the ws object
> ws = DirectCast(eApp.ActiveSheet, Excel.Worksheet)
>
> Dim headingArray() As String = {"STATE", "AGENCY", "TOTAL"}
> Dim rowArray() As String = {"B2", "C2", "D2"}
>
> CreateHeadings(headingArray, rowArray, ws, headingArray.Length -
> 1)
>
> dv.RowFilter = "app=1"
> dv.Sort = "state, agencyname"
> Dim colArray() As String = {"state", "agencyname"}
> WriteOutData(colArray, "app", ws, dv, colArray.Length - 1)
> End Try
> End Sub
>
> Private Sub WriteOutData(ByVal colArray() As String, ByVal product As
> String, ByRef ws As Worksheet, ByRef dv As DataView, _
> ByVal colLength As Integer)
> 'Writes out the data to the columns.
> Dim dr As DataRowView
> Dim rng As Range
> Dim rows As Integer = 0
> Dim col As Integer = 0
> Dim blnHeading As Boolean = False
> Dim temp As String = "" 'Temporary string to hold the state name
> Dim nTotal As Integer = 0
>
> rng = ws.Range("B3")
> rng.Select()
>
> For Each dr In dv
> For col = 0 To colLength
> If col = 0 Then
> 'We want to create 1 state label per state; therefore if
> the agency is in the same state don't reprint the state.
> If String.Compare(temp,
> CType(dr.Row(colArray(col).ToString()), String)) <> 0 Then
> temp = CType(dr.Row(colArray(col).ToString()), String)
> rng.Offset(rows, col).Value = temp.ToString()
> GetCount(nTotal, product, dv, temp.ToString())
> blnHeading = True
> Else
> rng.Offset(rows, col).Value = ""
> End If
> Else
> 'Print out the other values.
> rng.Offset(rows, col).Value =
> dr.Row(colArray(col).ToString())
> If col = colLength And blnHeading = True Then
> col += 1
> rng.Offset(rows, col).Value = nTotal.ToString()
> col -= 1
> blnHeading = False 'reset the flag
> End If
> End If
> Next col
> If col = colLength Then
> col = 0
> End If
> rows += 1
> Next
> End Sub
> --