Home > Language Reference > Classes > RecordDB

LookupUniqueID Function

Moves the cursor to the record identified by its UniqueID primary key.

Syntax

Public Function LookupUniqueID(ByVal lUniqueID As Long) As Long

ParameterDescription
lUniqueIDUnique identifier of the record to jump to

Remarks

The LookupUniqueID function positions the cursor on a record, designated by its primary key UniqueID, and return the record index within the RecordDB object.

An error occurs if the lUniqueID value does not correspond to a record in the recordset.

In the following example, when the main form in the test application is loaded, we create a database that is populated with 10 records. These records are added to the List1 List, their UniqueID being stored in the ItemData property of each list item.

When the user selects an item in the List, we retrieve its UniqueID and position the cursor on the corresponding record with the LookupUniqueID method of the RecordDB class.

Dim db as new RecordDB
Dim rec as new StreamRecord
Dim OneInteger as Integer
Dim OneString as String

Private Sub Form_Load()
Dim i as Integer
  'create database
  db.OpenByName "TestDB",hbModeCreateAlways+hbModeReadWrite+hbModeShowSecret,"data","ZZZZ"
  'Add records
  For i=0 to 9
    rec.Clear
    rec.Write i
    rec.Write " item " & Cstr(i)
    db.NewRecord rec
  Next i
  db.Close
  
  'Now Read records and fill the list1 object
  db.OpenByName "TestDB",hbModeOpenExisting+hbModeReadWrite,"data","ZZZZ"
  For i=0 to 9
    set rec=db.Record(i)
    rec.Read OneInteger
    rec.Read OneString
    List1.AddItem OneInteger & " : " & OneString ,rec.UniqueID
  Next i
  db.Close
End Sub

Private Sub List1_Change()
Dim lIndex as long
  if List1.ListIndex<0 then Exit sub
  'Open the Database
  db.OpenByName "TestDB",hbModeOpenExisting+hbModeReadWrite,"data","ZZZZ"
  'Move the cursor to the selected UniqueId
  lIndex=db.LookupUniqueID(List1.ItemData(List1.ListIndex))
  'Read the record
  Set rec=db.Record(lIndex)
  rec.Read OneInteger
  rec.Read OneString
  Msgbox "Db cursor moved to record with UniqueId= " & rec.UniqueID  & "\n at index : " & lIndex & "\nRecord Data=" & OneInteger & " and " & OneString
  db.Close
End Sub

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A