Results 1 to 4 of 4

Thread: [RESOLVED] Database to Flexgrid. Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Posts
    17

    Resolved [RESOLVED] Database to Flexgrid. Help

    For some reason that I do not know of, The flexgrid is not showing the first fields inside my database. what is wrong?
    why will it not show the first field inside my database?
    how do I fix this error?

    Code:
    Private Sub LoadRec()
    'THIS WILL LOAD DATABASE TO REFLEX GRID
    Dim Y As String
    Dim Rowcount As Integer
    Rowcount = 2
    Set DB = OpenDatabase(App.Path & "\Database\Products.mdb")
    Y = "select * from Inventory where number <> ''"
    Set Rec = DB.OpenRecordset(Y, dbOpenSnapshot)
    If Rec.EOF = False Then
        Rec.MoveNext
        Do While Not Rec.EOF 'THIS WILL READ THE ROWCOUNT 1 BY 1 UNTIL IT REACHES 6 THEN ENDS
            If Rowcount >= 6 Then
               Grid.Rows = Grid.Rows + 1
            End If
            'THIS WILL READ THE DATABASE FIELDS
        Grid.TextMatrix(Rowcount, 0) = Rec!Number
        Grid.TextMatrix(Rowcount, 1) = Rec!Name
        Grid.TextMatrix(Rowcount, 2) = Rec!Price
        Grid.TextMatrix(Rowcount, 3) = Rec!Quantity
        Grid.TextMatrix(Rowcount, 4) = Rec!Vendor
        Grid.TextMatrix(Rowcount, 5) = Rec!Description
        Rowcount = Rowcount + 1
        Rec.MoveNext
        Loop
        DB.Close
    End If
    End Sub

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Database to Flexgrid. Help

    Langamer

    If I understand you properly ..

    The flexgrid is not showing the first fields
    ... means that all these statements are not executed

    Code:
    Private Sub LoadRec()
        'THIS WILL LOAD DATABASE TO REFLEX GRID
        Dim Y As String
        Dim Rowcount As Integer
        Rowcount = 2
        Set DB = OpenDatabase(App.Path & "\Database\Products.mdb")
        Y = "select * from Inventory where number <> ''"
        Set Rec = DB.OpenRecordset(Y, dbOpenSnapshot)
        If Rec.EOF = False Then
            Rec.MoveNext
            Do While Not Rec.EOF 'THIS WILL READ THE ROWCOUNT 1 BY 1 UNTIL IT REACHES 6 THEN ENDS
                If Rowcount >= 6 Then
                   Grid.Rows = Grid.Rows + 1
                End If
                'THIS WILL READ THE DATABASE FIELDS
                Grid.TextMatrix(Rowcount, 0) = Rec!Number
                Grid.TextMatrix(Rowcount, 1) = Rec!Name
                Grid.TextMatrix(Rowcount, 2) = Rec!Price
                Grid.TextMatrix(Rowcount, 3) = Rec!Quantity
                Grid.TextMatrix(Rowcount, 4) = Rec!Vendor
                Grid.TextMatrix(Rowcount, 5) = Rec!Description
                Rowcount = Rowcount + 1
                Rec.MoveNext
            Loop
            DB.Close
        End If
    End Sub
    Actually, now that I think about it, I think this is the problem
    Perhaps you mean Rec.MoveFirst?

    Spoo

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Posts
    17

    Re: Database to Flexgrid. Help

    lol, that literally fixed my problem for ages. Freaking teacher giving me the wrong codes.
    So Rec.Movefirst shall read the first field of my table inside the database? is that correct?
    and rec.movenext shall read the next field which is the second field ignoring the first field of my database?
    thanks Spoo.

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: [RESOLVED] Database to Flexgrid. Help

    Langamer

    So Rec.Movefirst shall read the first field of my table inside the database?
    is that correct?
    Sort of, but not the way I would phrase it ...

    To start with, it might be useful to think of a database's terms using
    an Excel spreadsheet analogy.
    • Records in a database are like rows in a spreadsheet
    • Fields in a database are like columns in a spreadsheet.


    MoveFirst sets the "pointer" to the first record in the table.

    It's like reading the first row in a spreadsheet.
    So the field values returned would the all of the columns for row 1.

    MoveNext advances the "pointer" to the second record in the table.
    So no, it does not do this ...
    and rec.movenext shall read the next field which is the second field ignoring the first field of my database?
    Rather it's like now looking at row 2 in a spreadsheet.
    It does not ignore the first field.

    Does that help clear things up?

    Spoo

Tags for this Thread

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