Filter from control value

In Base is there a way to set a form’s filter property to use the value of another text or numeric control?

For example below, I want a control named FromLookup to be the value of ID that I’m filtering for:

image description

In this case FromLookup would evaluate to a value, like 11 for example. The way it is it tries to run test.ID = FromLookup which fails because FromLookup doesn’t exist as a field. I can put in test.ID = 11 and that works. But what I fail to see is how to use another value here to get inserted into the SQL, like something named FromLookup that evaluates to 11.

I would like my main form to be filtered not by a subform, but rather by the current value of a list box.

You need to use a macro.

'Get value from control'
	myData = FromLookup.Data 'or Value or whatever'
'Create filter'
	myFilter = "(`test`.`ID` = " & myData & ")"
'Insert filter in form properties'
	oForm.Filter = myFilter
'Reload form'
	oForm.Reload()

Sample: SelectCompanyByFilter3.odb

Thanks! Don’t know why I had my head stuck in thinking that the property value could be evaluated, when it’s just a simple string.

Just curious. Why do you put a tick on the end of your remarks? BTW, it works great.

It stops the comment coloring (green) from carrying on to the next code line. Just a formatting situation.