Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For..Next with FlexGrid

Posted on 1999-07-07
3
Medium Priority
?
138 Views
Last Modified: 2012-05-04
I'm using a For..Next loop to search through a database.  Every first instance of a set of data is placed in a flexgrid(grdCompletions).  If it already exists in the grid, then it should go through the loop again else add to the grid.  Well anyways, the problem I'm having is that it's adding the row of data to the grid for how many rows are already in the grid. For example, the first set is added once, the second twice, the third four times, the fourth 8 times etc.  What is wrong with my For.. Next statement?  (As you can see, I've tried using a Goto statement but doesn't work) -->

                 
                For NRows = 1 To grdCompletions.rows - 1
                    'see if 2 values are similar
                    If  {statement}          Then
                        'if 2 previous values are similar  then see if third is  -- don't add to grid
                         If
                        {statement}
                         End If
                     'Row found, go to next completion
                     GoTo Next_Completion
                 
          Else
                         
             'enter data into grid -- doesn't already exist
                 {statement}        
    End If
                   
        Next
Next_Completion:
      rsCompletions.MoveNext
0
Comment
Question by:valvoj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:Inteqam
ID: 1522457
try to debug it , and see the state of the conditions

0
 
LVL 3

Accepted Solution

by:
Gordonp earned 160 total points
ID: 1522458
You are only exiting the loop if you find an entry, but your adding the data to the grid every iteration.

You should loop throught the grid and check the data. Then after the loop add the data if it has not been found.

ie.

Dim bFound as Boolean
For nRows = 1 To grdCompletions.rows - 1
    'see if 2 values are similar
    If  {statement} Then
    'if 2 previous values are similar  then see if third is  -- don't add to grid
        If
            {statement}
        End If
        'Row found, go to next completion
        bFound = True        
        Exit For
    End If
Next

If Not bFound then
    'enter Data into Grid
    {Statement}
End If

Hope this helps
Gordon
0
 

Author Comment

by:valvoj
ID: 1522459
thanks for the quick answer Gordonp !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question