How to create Base form to enter values for row update?

I want to create a form with 2 text boxes in it for data entry into a single table. The 1st will contain the primary key and the 2nd will contain an integer to update for another column in that row.

In other words:
[ type primary key here ] [ type integer here ] then pressing ENTER will run the update query with these 2 variables, then reset the form.

Can Libreoffice Base do this? I know that I will need to script the SQL statement, but I don’t even understand how to make the form have fields for variables.

Any hints appreciated.

Hi

It is not necessary to create a specific one. Forms have the Filter feature:

1 - Click the tool Form-Based Filters

2 - Type the searched value in its text box, apply the filter,
Filer2

3 - Update the record.

4 - Unapply or Reset the filter.
Filter3

[EDIT]

Without macro would be possible to create a form with a subform. In the main form you type the ID and the link is made to display the related record in the subform. However this requires adding a macro to avoid having to accept the entry in the main form (and allow the update of the subform).

So, since it takes a macro, the easiest way is to entirely program. In the UpdateForm.odb attached the form is based on the Invoices table.

The macro begins with three constants that define the name of the table and the fields concerned. Simply adjust these constants: name of table and fields to be processed (and of course change the source of the form).

Warning: to meet the “specifications”, no validation is required before updating data. Only messages in case the fields are empty and that the ID is not found.

  • InitForm procedure called when loading form
  • UpdateQuery procedure called when key pressed (Enter key) in the “Integer” field

Regards

Thanks, Pierre, but that won’t work. I need the form to pass 2 parameters to an UPDATE query when the user enters a number and carriage return. (I’m actually using a barcode scanner, which does the equivalent). I can’t have the user mucking around with clicking on buttons like filters.

This is really easy to do with the form builder in Access, but I can’t figure out how to get libreoffice to do it. So how do I get a text box on a form to give me input to my script variable?

Thanks for going to all the trouble of creating an example! I’m looking at your form in edit mode, but I’m not sure how to get to the macros. The control menu doesn’t seem to work.

To edit the macro: ToolsMacrosOrganize MacrosLibreOffice Basic (or Alt+F11) then unfold UpdateForm.odbStandardModule1