devxlogo

Fast Database Lookups

Fast Database Lookups

Visual Basic doesn’t have a procedure like the DLookUp function that Access has. You can use thisprocedure in VB to receive the Name of an object by ID:

 Public Function MyDLookUp(Column As _        String, TableName As String, _        Condition As String) As VariantDim Rec As RecordsetOn Error GoTo MyDlookUp_Err' gCurBase is a global variable that ' holds the database that is currently ' openedSet Rec = gCurBase.OpenRecordset_        ("Select * From " & TableName)Rec.FindFirst ConditionIf Not Rec.NoMatch Then        ' return the requested field if         ' matching        MyDLookUp = Rec(Column)        Exit FunctionEnd If' return -1 if there is no match, or any ' other errorMyDlookUp_Err:        MyDLookUp = -1End Function

devx-admin

Share the Post: