formModel.absolute(i) goes to wrong record

I have a form with a subform set up for navigation. Essentially, the subform contains a listbox (tied to a cache table field) of the names of all records in the table of the main form, along with a “Go” button, which launches a macro. The macro grabs the integer value (i) of the selection in the dropdown and then

msgbox "Going to: " & CStr(i)
oMainForm.absolute(i)

Now, if I select in the listbox the name of the very last record in the listbox, the msgbox correctly displays the id number of that record, but then the main form jumps to the very first record, even if it’s already on the very last one. I’ve checked that the form is ordered by id numbers ascending, so that’s not the problem. If I select the name of the very first record, it says it’s going to 1 and then it does.

Hello,
absolute will go to the record pointed to in the result set starting with 1 (see > ◆ absolute()).
.
It is not clear what value you are using from the list box - ID or SelectedItemPos or whatever the integer value (i) is or something else.
.
My testing has this working using SelectedItemPos +1 (value starts at 0). The records in the form and those in the list box are the same and in the same sequence. If you want to use something like an ID then absolute is not a good way to go. Using that, you may need to search through records to find a match.

Hmmm… I’ve never heard of SelectedItemPos. I’m using ID. Maybe I should be using SelectedItemPos, just in case there ends up being a break in ID numbers (for whatever reason).

Isn’t there a method for making the form jump to a certain row, just like if I had changed the number in the navigation bar? I just tried:

oMainFormController.formOperations.execute(1, i)

but it complained that parameters need to be passed, so I tried

oMainFormController.formOperations.execute(1, Position = i)

but it still complained about parameters. Is there a special way I need to pass parameters to the formOperations.execute() command for this to work? Surely there’s a way to do it.

Also, @Ratslinger, how would I go about using SelectedItemPos? Is it similar to oControl.selectedValue?

Whether you use your execute or oMainForm.absolute(i) or the navigation bar, it is all the same - going to a specific record in the result set. The first record is 1, the second is 2 and so on. Has nothing to do with using any key or value from the table itself. LO Base has no search function for lookup.

If you want to get the selected item number from the list box (position in the list starting with zero), the easy method is using the returned event information to the sub such as:

Sub get_selection(oEvent)
    Dim iSelected as Integer
    iSelected = oEvent.Source.SelectedItem
    msgbox "Going to: " & iSelected
    oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_FORM_NAME")
    oForm.absolute(iSelected +1)
End Sub

.
You can also get this from the list box by obtaining the View of the control:

    oLBctrl = GET_YOUR_LISTBOX_CONTROL_HERE
	Doc = ThisComponent
	DocCtl = Doc.getCurrentController()
'Get VIEW for listbox
  	CtlView = DocCtl.GetControl(oLBctrl)
	iSelected = CtlView.SelectedItemPos

.
Please discontinue using cryptic code such as:

oControl.selectedValue

oControl can be almost anything and therefore there is little way (except to guess) to know what is actually being referred to.

Thanks for your help! In the future, i will try to always explain what things like that mean.

In this case, oControl was intended to mean the list box control object.