Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First you need to have available the specifics you are looking for in this grid. In your example, CustID & ItemID (these of course must columns be in the grid you are searching). Starting with the first record in the form (or subform), access column for CustID & see if a match for search item. If so, get column for ItemID & see if match for search item. If both = True you have the record. Get the bookmark & use to set highlight for row in grid.

Sample code (your names will vary):

Sub SetSelectedRecord
    Dim oDoc         as Object
    Dim DocCtl       as Object
    Dim oForm        as Object
    Dim oColumns     as Object
    Dim oCell        as Object
    Dim oField       as Object
    Dim x            as Integer
    Dim iCount       as Integer
    Dim sel(0 to 1)
    oDoc = ThisComponent
    DocCtl = oDoc.getCurrentController()
    oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_FORM_NAME")
    oForm.first()
    iCount = oForm.getCount()
    oColumns = oForm.getColumns()
    for x = 0 to iCount
        oCell = oColumns.getByName("COLUMN_NAME")
        If oCell.Value = VALUE_TO_CHECK then
            oCell = oColumns.getByName("COLUMN_NAME")
            If oCell.Value = VALUE_TO_CHECK then
                oField = oForm.getByName("GRID_CONTROL_NAME")
                sel(0) = oForm.getBookMark()
                CtlView = DocCtl.getControl(oField)
                CtlView.Select(sel)
                Exit for
            end if
        end if
        oForm.next()
    next x
End Sub

First you need to have available the specifics you are looking for in this grid. In your example, CustID & ItemID (these of course must columns be in the grid you are searching). Starting with the first record in the form (or subform), access column for CustID & see if a match for search item. If so, get column for ItemID & see if match for search item. If both = True you have the record. Get the bookmark & use to set highlight for row in grid.

Edit 8/6/2017 - corrected code to get the proper iCount value.

Sample code (your names will vary):

Sub SetSelectedRecord
    Dim oDoc         as Object
    Dim DocCtl       as Object
    Dim oForm        as Object
    Dim oColumns     as Object
    Dim oCell        as Object
    Dim oField       as Object
    Dim x            as Integer
    Dim iCount       as Integer
    Dim sel(0 to 1)
    oDoc = ThisComponent
    DocCtl = oDoc.getCurrentController()
    oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_FORM_NAME")
    oForm.last()
    iCount = oForm.getRow()
    oForm.first()
    iCount = oForm.getCount()
    oColumns = oForm.getColumns()
    for x = 0 1 to iCount
        oCell = oColumns.getByName("COLUMN_NAME")
        If oCell.Value = VALUE_TO_CHECK then
            oCell = oColumns.getByName("COLUMN_NAME")
            If oCell.Value = VALUE_TO_CHECK then
                oField = oForm.getByName("GRID_CONTROL_NAME")
                sel(0) = oForm.getBookMark()
                CtlView = DocCtl.getControl(oField)
                CtlView.Select(sel)
                Exit for
            end if
        end if
        oForm.next()
    next x
End Sub