By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Filling in Data Table Using Loop: Check to see if Data Changes

P: 28
I'm filling in a Report with SQL data using VB code. I'm using LOOP and MoveNext. Before using MoveNext, I would like to be able to check whether the new data is equal to the previous data that was added. I'm not sure if MovePrevious is the best way to accomplish this. Here's an example of my code:

With rs
.MoveFirst
strData = Trim(!data)

Do While Not .EOF

If Not .BOF Then
.MovePrevious
strDataPrev = Trim(!data)
.MoveNext
End If

If (strData <> strDataPrev) Then

'The record is new

End If

.MoveNext
Loop
.Close
End With

Will this work? Or is another method better?
Aug 31 '07 #1
Share this Question
Share on Google+
3 Replies


Tig201
100+
P: 103
[quote=nico3334]I'm filling in a Report with SQL data using VB code. I'm using LOOP and MoveNext......QUOTE]

The first thing I would Note is that you are not setting “strData” After the first Record. Next I would recommend setting “strDataPrev = strData” after you check to see if they are equal as apposed to moving backwards and forwards through the table.
Aug 31 '07 #2

QVeen72
Expert 100+
P: 1,445
Hi,

Open a New Recordset for the condtion and check with the data.. Why open whole recset and loop thru and do the "Moves"..?

Regards
Veena
Sep 2 '07 #3

P: 28
Hi,

Open a New Recordset for the condtion and check with the data.. Why open whole recset and loop thru and do the "Moves"..?

Regards
Veena
Sorry, I added in some extra code to try to describe my problem better.

I'm retrieving data from a sql table using .movenext and loop. When it is inserting the data, I would like it to check whether the next record it will be adding is equal to the last record it added. If it not is equal, I want to add an occurence to an array. Does this code look ok? Thanks.
''''''''''''''''''''''
Dim arrData() As String
ReDim arrData(Col, 0)

With rs
.MoveFirst
strData = Trim(!Data)

Do While Not .EOF

If Not .BOF Then
.MovePrevious
strDataPrev = Trim(!Data)
.MoveNext
End If

If (strData <> strDataPrev) Then

'Add Occurence to Array
ReDim Preserve arrData(UBound(Col) + 1)

End If

arrData(Col, 0) = strData

.MoveNext
Loop
.Close
End With
Sep 5 '07 #4

Post your reply

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