Operating System: Windows 10
Hello!
I am new to using OpenOffice, although I have some beginner-level experience using Microsoft Access. I am currently making a database to archive very old customer records that will be destroyed.
The way I have it set up is with 3 tables, one for basic information for each customer and two others that I am using to add multiple pictures as subforms in the main form.
I have one main form that displays the customer information.
In order to make the database user-friendly, I have tried to add a search control that will allow users to search the records by name.
I searched these forums for help and found this thread: viewtopic.php?f=13&t=6256
which discussed using a combo box and macros to filter records, and this thread: viewtopic.php?f=39&t=6834
which expanded upon the previous thread but added more to the macro to avoid data loss.
After a bit of trial and error I have added the search control to my form. When I begin typing in the combo box it works as it should by autocompleting/prompting a customer name, however when i press return or click on the suggested name, the form does not update to the selected customer record. After more lurking and searching I can't seem to find a solution, and would really appreciate some help.
Here is the code for my current macro:
Code: Select all
Sub SearchByName
dim oFilter as object
dim oFormCtl as object
dim doMove as boolean
on local error goto SearchByNameError
oFormCtl = ThisComponent.Drawpage.Forms.getByName("PatientRecords")
if oFormCtl.isModified then
doMove = doUpdateRecord( oFormCtl, oFormCtl.isNew )
else
doMove = TRUE
end if
if doMove then
oFilter = oFormCtl.getByName("search_combobox")
if oFilter.CurrentValue <> "" then
oFormCtl.Filter = "Name LIKE " + "'"+oFilter.CurrentValue+"'"
oFormCtl.ApplyFilter = True
else
oFormCtl.ApplyFilter = False
end if
oFormCtl.Reload
end if
exit sub
SearchByNameError:
resume next
End Sub
function doUpdateRecord( aDataForm as variant, aNew as boolean ) as boolean
doUpdateRecord = FALSE
if aNew then
aDataForm.InsertRow
else
aDataForm.UpdateRow
end if
doUpdateRecord = True
end function
Code: Select all
SELECT DISTINCT "Name" FROM "Patients"