Populate MSFlexGrid with Data from Mysql

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
SlythieAsked:
Who is Participating?
 
FER_GConnect With a Mentor Commented:
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

FerG
Saludos
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
        .Close
        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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.