Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping with views

Status
Not open for further replies.

iwells

Programmer
Oct 2, 2012
284
CA
A while back Ettienne told me to use the format:

Do While view.GoNext
CODE​
Loop

but when I use the following code it if I place a watch on the value of strTemp it changes when testing, assigning and looping indicating that the view is moving records and I'm not sure why:


Dim vCSOPTFD As AccpacCOMAPI.AccpacView
Dim strTemp As String

mDBLinkCmpRW.OpenView "CS0012", vCSOPTFD


vCSOPTFD.Browse "OPTFIELD = ""GLJOBSET""", True
vCSOPTFD.GoTop


Do While vCSOPTFD.GoNext

strTemp = Mid(vCSOPTFD.Fields("VALUE").Value, 1, 4)

Loop
End Sub

My data show there are 45 rows from sql server, but when looping it will only loop 15 times or even less and I can't understand why the cursor is moving on the test of the condition, the assignment to str temp and on loop.

 
I never use GoNext, I always use .Browse and .Fetch. You probably should set a filter, then don't use .Browse, just use GoTop/GoNext.
 
Ok, I'm really new to using the views, so what would be the proper syntax under the way you'd do it?
 
FYI.... .Fetch is deprecated.
But it still works identical to .GoNext - they are interchangeable.
They added .GoTop, .GoNext, .GoPrevious & .GoBottom to give added functionality. Prior to that all you could do is forward browsing with .Fetch.

I don't do a .GoTop after opening a view - but I guess it does not hurt.

Your code should be reading all records - are you sure there are 45?






Sage 300 Certified Consultant
 
100% sure and I posted this because I can place a watch on strTemp and every line of code causes the value to change and I don't understand it. When I step from the do while line to the strTemp assignment line there's a change in the value of Mid(vCSOPTFD.Fields("VALUE").Value, 1, 4), after the assigment of Mid(vCSOPTFD.Fields("VALUE").Value, 1, 4) to strTemp there's a change in the value of Mid(vCSOPTFD.Fields("VALUE").Value, 1, 4) and after loop there's a change in the value of Mid(vCSOPTFD.Fields("VALUE").Value, 1, 4).

Basically it looks like on every line of code .GoNext gets executed and I've copied the code exactly as it is.

First, is CS0012 actually CSOPTFD (details table)? In a previous sub procedure that's lost focus (the code I'm copying is the only code in the current sub) I use CS0120 and InternalSet 256, do I need to adjust my code for something related to that?
 
In terms of references the only ones I have in the project are VB for Apps, MS Forms 2.0, OLE Automation and Accpac COM API 1.0
 
CS0012 is the optional fields detail table.



Sage 300 Certified Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top