Macro to position Form to Row

Sorry to keep bothering you guys. I just seem to struggle trying to learn from the documentation on my own.

I have a table with two columns, a one-character “Route” and a 255-character “Alert.” The table is fixed at seven rows with routes A-F and Z.

I am trying to build a form where the user could use a LIst Box to position to a particular row and then edit the Alert text. I have the List Box, populated by a SQL SELECT on the Route column. A have a Text Box linked to the Alert column. I actually can edit each alert by scrolling through the table with the Navigation Bar, but that’s not really how I want it to work.

What I want to be able to do is use the List Box to position to a particular row.

I know this much. I need a macro on the List Box Changed event. The macro wants to start out

Sub GoToRow(oEvent AS OBJECT)
	oField = oEvent.Source.Model
 	oForm = oField.Parent

What next?

Thanks,
Charles

If you can’t program, you won’t get anywhere with this approach. You have no more than 7 entries to select from.
Put these 7 items in a main form and the related item in a subform.

You could set the filter for sub-form based in table Alert. As I proposed at

How to create a query between two dates using dates from a date box on a form and display results in a subform

replacing of course the Date Boxes with your ListBox.
BUT with only (limited to) 7 rows, it should be much more practical as said above by @Villeroy I think.

    Dim r As String ' string for the Route id char
    [...]
    If IsEmpty(oField.currentValue) Then
	    MsgBox "You must select the route!"
	    Exit Sub
	Else r = oField.currentValue 'set the parameter
	End If

BUT…

The insult was unnecessary.

EDIT

Dim rid As Long
[...]

as if I remember you have 3 columns
[rid (pk - autovalue) | route (char) | alert]
So the ListBox value = rid
and display = route (column 0 of the LB source SQL).

:question:

This is a sample. But reiterating that for just 7 records it would be more practical…
REMARKS

  1. I placed Text Box 1 (= rid) just for control purpose. In practice it should be deleted as not useful for operator.
  2. To navigate in the records one needs first to place cursor into TextBox (got confused at first!).
    Alertas.odb (14.3 KB)

My way to dovthis is

  • Adding a grid control at the side
  • and using a filter-table to reduce entries

Straightforward solution via Form Wizard.