Results 1 to 12 of 12

Thread: Check item in flexgrid with ADO field items

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Post Check item in flexgrid with ADO field items

    Hello

    I have a flexgrid in which 40 columns are in 1 row;

    I wish to check these columns (0 to 40) with content ADO field but can't get out - what am I doing wrong :

    Code:
    rs_MySQL_Algemeen.MoveFirst
    Do Until rs_MySQL_Algemeen.EOF = True
    
    .Col = 0
    For Teller = 0 To .Cols - 1
    
    If Trim(.Text) = Trim(rs_MySQL_Algemeen!velden) Then
    
    MsgBox .Text & "  --  " & rs_MySQL_Algemeen!velden
    
    Else
    
    .Col = Teller
    
    End If
    
    Next Teller
    
    rs_MySQL_Algemeen.MoveNext
    Loop

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,429

    Re: Check item in flexgrid with ADO field items

    In your loop your setting the current .Col after the compare statement.
    You also need to set the .Row property
    What is s_MySQL_Algemeen!velden?
    Is the same for every column?

    Better use the .TextMatrix() property.
    Specify the row and the column and you get the text/content.
    Code:
    If Trim(.TextMatrix(lRow, Teller) = Trim(rs_MySQL_Algemeen!velden) Then
    '
    End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Check item in flexgrid with ADO field items

    What is s_MySQL_Algemeen!velden? recordset
    Is the same for every column? Yes - In each column flexgrid there are different values that must be compared with all values entered in ado.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,352

    Re: Check item in flexgrid with ADO field items

    Quote Originally Posted by MarcDv View Post
    What is s_MySQL_Algemeen!velden? recordset
    No... that's not quite right, now is it? s_MySQL_Algemeen is the recordset, s_MySQL_Algemeen!velden should be a field in the record set...


    Quote Originally Posted by MarcDv View Post
    Is the same for every column? Yes - In each column flexgrid there are different values that must be compared with all values entered in ado.
    The question should be why are you comparing the columns in the grid to the same one value? The code as it is, compares all of the values in the one row of a grid to a single value - one row, one field - in the recordset. It is NOT comparing to all --- ah... ok, I see the moveNext ... ok.. so it's comparing all of the columns in the grid to the one field in each of the rows.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Check item in flexgrid with ADO field items

    I wish every column in the flexgrid to be checked with ADO field.

    Flexgrid :

    ---------------------------
    -- A -- E -- D -- F -- H --
    ---------------------------

    ADO FIELD :

    A
    B
    C
    D
    E
    F
    G
    H
    ...

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,476

    Re: Check item in flexgrid with ADO field items

    If you want to compare every column to every field and assuming there are the same number of rows and columns as fields and records then you would use a loop that looks more like this.
    Code:
    cRow=1
    Do Until RS.Eof    
        For x=0 to 39
            if .TextMatrix(cRow,x)=RS(x) then
                 'match
            else
                 'no match
            end if   
        Next
        cRow=cRow+1
        RS.MoveNext
    Loop

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,800

    Re: Check item in flexgrid with ADO field items

    Just trying to get this straight in my head what you mean and what your data looks like.

    In your post #5, I think your first 5 columns of your grid have the values "A", "E", "D", "F" and "H", respectively. Is that correct?
    Then you LIST something A through H (assuming there are more in your 'list'. Are these values all on one row in your table, like:

    Field1 = "A", Field2 = "B"..... etc? That is, if a query is done on that one row, your recordset would be rs!Field1 as "A", rs!Field2 as "B", ... etc?

    If that is all correct, are you then trying to compare Field1 with each of the columns in your grid, and then compare Field2 with each column in your grid, etc, until all Fields have been compared with every column?

    If so, what's the end game?
    Sam I am (as well as Confused at times).

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: Check item in flexgrid with ADO field items

    That's what I want. with vb I only get first column flexgrid

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,800

    Re: Check item in flexgrid with ADO field items

    Then modify your code to check each column...IOW, if your code is working for the first column, loop that code for each column. (Still, I don't quite understand WHY you are doing this---what are you trying to get to?...BTW, instead of using messageboxes, how about populating a list box with information like 'fieldName' and 'grid col #'?)
    Sam I am (as well as Confused at times).

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,800

    Re: Check item in flexgrid with ADO field items

    Again, based on info gleaned from post # 5, is that what you want?

    Checking rs as "A", then you check each column...the result would be " A was found in column 0 ". (IF "A" was found in some other column, a result could be like "A was found in column 38 "
    Then, checking rs as "B", the results would "B" was not found.
    Then, checking rs as "C", the resuts would again be "C" was not found
    Then checking rs as "D", the result would be " D was found in column 2 "
    then checking rs as "E", the result would be " E was found in column 1 "

    IS THAT YOUR END GAME?
    Sam I am (as well as Confused at times).

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,800

    Re: Check item in flexgrid with ADO field items

    I did a quick example...my form looks like this base on data in post 5:

    Name:  Capture.JPG
Views: 35
Size:  18.4 KB

    The result was:

    A was found in --Column 0
    D was found in --Column 2
    E was found in --Column 1
    F was found in --Column 3
    H was found in --Column 4
    or, more exact:

    A was found in --Column 0
    A was not found in --Column 1
    A was not found in --Column 2
    A was not found in --Column 3
    A was not found in --Column 4
    B was not found in --Column 0
    B was not found in --Column 1
    B was not found in --Column 2
    B was not found in --Column 3
    B was not found in --Column 4
    C was not found in --Column 0
    C was not found in --Column 1
    C was not found in --Column 2
    C was not found in --Column 3
    C was not found in --Column 4
    D was not found in --Column 0
    D was not found in --Column 1
    D was found in --Column 2
    D was not found in --Column 3
    D was not found in --Column 4
    E was not found in --Column 0
    E was found in --Column 1
    E was not found in --Column 2
    E was not found in --Column 3
    E was not found in --Column 4
    F was not found in --Column 0
    F was not found in --Column 1
    F was not found in --Column 2
    F was found in --Column 3
    F was not found in --Column 4
    G was not found in --Column 0
    G was not found in --Column 1
    G was not found in --Column 2
    G was not found in --Column 3
    G was not found in --Column 4
    H was not found in --Column 0
    H was not found in --Column 1
    H was not found in --Column 2
    H was not found in --Column 3
    H was found in --Column 4

    Sam I am (as well as Confused at times).

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,800

    Re: Check item in flexgrid with ADO field items

    My Code example (based on Post5 data ex)

    Code:
    Option Explicit
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    
    Private Sub Form_Load()
        popGrid
        Set cnn = New ADODB.Connection
        With cnn
            .Provider = "Microsoft.ACE.OLEDB.12.0"
            .ConnectionString = "User ID=Admin;password= ;" & " Data Source= " & App.Path & "\myDB.accdb"
            .CursorLocation = adUseClient
            .Open
        End With
        Dim sName As String
        sName = "Sam"
        Dim rs As New ADODB.Recordset
        rs.Open "select * from mytable where sName = '" & sName & "'", cnn, adOpenKeyset, adLockPessimistic
             Dim i As Integer, j As Integer
             For i = 2 To 9
                 For j = 0 To 4
                    If rs(i) = grid1.TextMatrix(0, j) Then
                        Debug.Print rs(i) & " was found in " & "--Column " & CStr(j)
                    Else
                       Debug.Print rs(i) & " was not found in " & "--Column " & CStr(j)
                    
                    End If
                 Next j
             Next i
        rs.Close
    End Sub
    
    
    
    
    Private Sub popGrid()
        grid1.TextMatrix(0, 0) = "A"
        grid1.TextMatrix(0, 1) = "E"
        grid1.TextMatrix(0, 2) = "D"
        grid1.TextMatrix(0, 3) = "F"
        grid1.TextMatrix(0, 4) = "H"
    End Sub
    Sam I am (as well as Confused at times).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width