Populate MSFlexGrid with Data from Mysql

Posted on 2009-04-15
Last Modified: 2013-12-26
Dear Experts,
I'm new with msflexgrid and im required to do some programming with it. I've setup my msflexgrid so that the user can enter values to each individual cells. However, now i want it so that whenever the user input a text and pressed enter on a very first column on each row, i want the second column to display values from mysql database. (ie. if the user entered an item_code of (BR02) in column 1, i want the 2nd column to get that item_code from mysql and then display the item_name). How am i suppose to do this? Thank you experts
Question by:Slythie
    1 Comment
    LVL 7

    Accepted Solution

    Slythie; I prepare you a code snippet to show you how you can do that.
    The code, suppose:
    ADO_Conn: is an open ADO connection to a MySQL database
    Review the msFlexGrid name, the table and fields name, because i use generic names.
    Col1: the col where the itemCode is
    Col2: the col where the ItemName will be

    Ing. Fernando D. Giletta
    San Francisco. Cordoba. Argentina
    Private Function ItemName(itemCode As String) As String
        Dim oRS As New ADODB.Recordset
        Dim sSQL As String
        sSQL = "SELECT ItemName from table1 where itemCode='" & itemCode & "'"
        With oRS
            .CursorLocation = adUseClient
            .Open sSQL, ADO_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
            If (Not (oRS.EOF)) Then
                ItemName = oRS.Fields("ItemName")
            End If
            Set oRS = Nothing
        End With
    End Function
    Private Sub grilla_AfterRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByVal NewCol As Long)
        With grilla
            If (OldCol <> NewCol) Or (OldRow <> NewRow) Then
                'if the oldCol is the col where the itemCode is...get the itemName of it
                If (OldCol = 1) Then
                    Dim code As String
                    code = .TextMatrix(OldRow, 1)
                    .TextMatrix(OldRow, 2) = ItemName(code)
                End If
            End If
        End With
    End Sub

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now