Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 10th, 2003, 01:48 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 5
How to SKIP in recordset?

Hi all, I am getting records from a table and display it in excel file BY MONTH. My problem is I read the recordset until EOF and I SELECT DISTINCT DATE FROM REPORT ... so it will display duplicate date in excel because it loop through the whole record set. UNLESS the date and exactly the same to other, it will stays in the same header. Else, it will display repeatedly in other header. My question is ... how do I skip recordset after I have done first recordset process? Like skip the rest which have the same MONTH as the previous processed records?
Code as below:-

======================================

.........

Dim strRow As Integer
Dim RowNumber As Integer

RowNumber = 5
strRow = 4

getData = "SELECT DISTINCT DATE FROM REPORT"
Set rs = cn.Execute(getData)

Do While Not rs.EOF

If rs.Fields("date") >= dtStartDate And rs.Fields("date") <= dtEndDate Then


'found = True

Dim pass As String
pass = rs.Fields("date")

Dim findArray() As String

findArray = Split(pass, "/")

'this is just to count how many items in each month
Dim getReport4 As String
Dim rs4 As New ADODB.Recordset

getReport4 = "SELECT COUNT (month(DATE)) AS TEMP FROM REPORT WHERE month(DATE)='" & findArray(0) & "'"
Set rs4 = cn.Execute(getReport4)

Dim temp1 As Integer

temp1 = rs4.Fields("TEMP")

' MsgBox "Date = " & rs.Fields("date") & " month = " & findArray(0) & " has counted " & temp1

getReport2 = "SELECT * FROM REPORT WHERE month(DATE)='" & Month(rs.Fields("date")) & "'"
Set rs2 = cn.Execute(getReport2)

If (strRow > 4) Then

.Cells(strRow - 1, 1).Value = "Date" ' cells (2, 1) means row 2 and column 1
.Cells(strRow - 1, 6).Value = "Bank Name"
.Cells(strRow - 1, 3).Value = "Bank Type"
.Cells(strRow - 1, 4).Value = "Amount $"
.Cells(strRow - 1, 5).Value = "Deposit / Withdrawal"
.Cells(strRow - 1, 2).Value = "Category"
.Cells(strRow - 1, 7).Value = "Comments"

'Header settings

.Rows(strRow - 1).HorizontalAlignment = xlHAlignCenter ' set header in center
.Rows(strRow - 1).Font.Bold = True ' set first row - header as font bold
.Rows(strRow - 1).Font.ColorIndex = 5 ' set header words in blue
.Range(.Cells(strRow - 1, 1), .Cells(strRow - 1, 1)).RowHeight = 30
.Range(.Cells(strRow - 1, 1), .Cells(strRow - 1, 7)).Interior.Color = RGB(180, 180, 180)

Do While Not rs2.EOF


'set the string equal to the row number to start on
strRow = "" & RowNumber & ""
.Range("A" & strRow) = Format(rs2.Fields("date"), "Medium Date")
.Range("F" & strRow) = rs2.Fields("bank_name")
.Range("C" & strRow) = rs2.Fields("account_type")
.Range("D" & strRow) = Format(rs2.Fields("amount"), "currency")
.Range("E" & strRow) = rs2.Fields("deposit_withdrawal")
.Range("B" & strRow) = rs2.Fields("category")
.Range("G" & strRow) = rs2.Fields("description")

'auto fit columns
.Range(.Cells(4, 1), .Cells(strRow, 8)).Select
xlsApp.Selection.Columns.AutoFit

rs2.MoveNext
RowNumber = RowNumber + 1
Loop

'set 2 blank rows between new banks
RowNumber = RowNumber + 3
strRow = RowNumber

Else


.Cells(strRow, 1).Value = "Date" ' cells (2, 1) means row 2 and column 1
.Cells(strRow, 6).Value = "Bank Name"
.Cells(strRow, 3).Value = "Bank Type"
.Cells(strRow, 4).Value = "Amount $"
.Cells(strRow, 5).Value = "Deposit / Withdrawal"
.Cells(strRow, 2).Value = "Category"
.Cells(strRow, 7).Value = "Comments"

'Header settings

.Rows(strRow).HorizontalAlignment = xlHAlignCenter ' set header in center
.Rows(strRow).Font.Bold = True ' set first row - header as font bold
.Rows(strRow).Font.ColorIndex = 5 ' set header words in blue
.Range(.Cells(strRow, 1), .Cells(strRow, 1)).RowHeight = 30
.Range(.Cells(strRow, 1), .Cells(strRow, 7)).Interior.Color = RGB(180, 180, 180)

Do While Not rs2.EOF

RowNumber = 5
'set the string equal to the row number to start on
strRow = "" & RowNumber & ""
.Range("A" & strRow) = Format(rs2.Fields("date"), "Medium Date")
.Range("F" & strRow) = rs2.Fields("bank_name")
.Range("C" & strRow) = rs2.Fields("account_type")
.Range("D" & strRow) = Format(rs2.Fields("amount"), "currency")
.Range("E" & strRow) = rs2.Fields("deposit_withdrawal")
.Range("B" & strRow) = rs2.Fields("category")
.Range("G" & strRow) = rs2.Fields("description")

'auto fit columns
.Range(.Cells(4, 1), .Cells(strRow, 8)).Select
xlsApp.Selection.Columns.AutoFit

rs2.MoveNext
RowNumber = RowNumber + 1
Loop

'set 2 blank rows between new banks
RowNumber = RowNumber + 3
strRow = RowNumber
End If

End If

rs.MoveNext
pass = ""

Loop

...............

Reply With Quote
  #2  
Old October 10th, 2003, 02:30 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,174 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 27 m 59 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
hey HB - let me try this one...

instead of declaring a new recordset, and then working with two of them... why don't you try this...

once you have your recordset, and you know what month you're working with, apply a filter like so

Code:
dim i as integer
           rsRecordset.addfilter "month(Date) LIKE '" & findArray(0) & "'"
           i = 0
           Do until rsrecordset.eof = true
                 i = i + 1
                 rsrecordset.movenext
           Loop
           rsrecordset.removefilter
           rsrecordset.movefirst
           rsrecordset.move 0,i


That should find all records where your month is the same, move through them, and count how many there are... then it will move to the first one, and then position itself on the last recordset WITHOUT the filter. All of this is not necessary if you pass the recordset to a public function by reference, and then just loop through until the month is not equal.
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old October 10th, 2003, 03:27 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 5
Hi FM ... there is no "addfilter" function in recordset properties ... right? I got error message for this

Reply With Quote
  #4  
Old October 11th, 2003, 09:38 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
addfilter??Ido't find it too..U can use sql statement according to the month sort..First diaplay 1th Month result, and add to displaying 2th Month result...

Reply With Quote
  #5  
Old October 12th, 2003, 11:14 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,174 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 27 m 59 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
guys.. I'm sorry.. I must have been smoking crack when I wrote that... it should be the following

Code:
dim i as integer
           rsRecordset.filter "month(Date) LIKE '" & findArray(0) & "'"
           i = 0
           Do until rsrecordset.eof = true
                 i = i + 1
                 rsrecordset.movenext
           Loop
           rsrecordset.filter adfilterNone
           rsrecordset.movefirst
           rsrecordset.move 0,i

Last edited by Fisherman : October 13th, 2003 at 09:06 AM.

Reply With Quote
  #6  
Old October 13th, 2003, 12:41 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
This is right! Thx Fisherman!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to SKIP in recordset?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway