[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Populate MSFlexGrid with Data from Mysql

Posted on 2009-04-15
Medium Priority
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

Accepted Solution

FER_G earned 1000 total points
ID: 24156494
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


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 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