Home > Enterprise >  Self-referring query as row source for list box
Self-referring query as row source for list box

Time:08-19

I'm trying to make a list box in table view in MS Access, where the list values is dependent on the current record. I does indeed work sometimes, but its very unstable, and sometimes it doesn't work, and then it works again.

The following sql query is the Row Source for the list box:

SELECT tbl1.TAG FROM tbl1 WHERE tbl1.[Tag kode] =[KomponentTagkode]; 

The field [KomponentTagKode] is another field in the same table as the list box.

Is there any syntax than can be improved to make this a stable working solution?

I'm aware that this can probably done by using VBA, although I'm not sure which event should pass the change. But I feel that the solution I have already used is more elegant, and I would prefer it if it could be stable.

CodePudding user response:

As mentioned in comments, you need to requery the row source of the list box every time the current record changes.

Add the below to the form's code-behind. Just change the control name to that of your list box.

Private Sub Form_Current()
    YourListBoxControlName.Requery
End Sub
  • Related