Where is findfirst?
From Apache OpenOffice Wiki
< Documentation | FAQ | Databases | MS Access
Where is findfirst?
Base does not appear to have a FindFirst function on the rowset like MS Access, what is the equivalent Base function?
MSAccess VBA example:
Say there is a VB combo box which lists all the prospects in the database and allows the user to select a particular prospect and then have the form automatically go to that person's data record.
Private Sub Find_Combo_AfterUpdate()
Dim strCriteria As String
strCriteria = "[Prospect_ID] =" & Me.Find_Combo
Me.recordsetclone.FindFirst (strCriteria)
If me.recordsetclone.NoMatch Then
MsgBox "No entry found"
Else
Form_F_Prospects.Bookmark = me.recordsetclone.Bookmark
End If
End Sub
For this type of simple single column search, it is easy enough to create our own find first equivalent with AOO Basic:
Sub Find_Combo_AfterUpdate( OEv as Object)
' Oev is the event object automatically sent to sub procedure call
' Oev will have a property Source that is the control that triggered
' the call to this procedure
Dim oForm as variant ' The dataform obejct
Dim oComboBox as variant ' The combobox control
Dim oBkMark as variant
oForm = oEv.Source.Model.Parent
oComboBox = oForm.getByName( "Find_Combo" )
oBkMark = FindFirst( oForm.CreateResultSet(), "Prospect_ID", oComboBox.Text )
' oForm.CreateResultSet() is here equivalent to me.recordsetclone
if not IsEmpty( oBkMark ) then
oForm.moveToBookmark( oBkMark )
else
msgBox( oComboBox.Text & " not found" )
end if
end sub
function FindFirst( oRS as variant, ColName as string, SearchVal as string ) as variant
' oRS is a resultSet object
' ColName is the name of a column in the resultset
' SearchVal is
dim colIDX as integer
dim NotFound as variant
FindFirst = notFound
colIDX = oRS.FindColumn( ColName )
oRS.First
do
if oRS.getString( colIDX ) <> Searchval
oRS.Next
if oRS.isAfterLast then
exit do
endif
else
FindFirst = oRS.getBookMark
exit do
end if
loop while oRS.isAfterLast <> True
end function