simple listbox query inside form

godisaclog

New member
Local time
Today, 13:15
Joined
Jan 21, 2014
Messages
3
Hi everyone,

I have a really novice question, but I've spent a few hours trying this out and I don't understand why I'm not getting it!

I have a form with a list box. This list box has a row source that I've set as a query for five different fields with a where clause. This where clause should pick up a value that is already within the form. And this is where I think it's going wrong, because if returns no results, but if I set it to point at the same value from another form (previous to this one, it does work). So there is something about the order or something so that this variable isn't passed to my listbox when it executes.

So, my list box has: select ID, title from table where ID = [Forms]![CurrentFormName]![ID]

and it doesn't work.

However if I add a text field and set that to point at =[ID] then this does display the ID. And if I amend my query to point at this text field using the same convention above, that doesn't work either.

I presume I am mis-referencing, or there is something in the order that the listbox loads and it does this before the ID is set?

Can anyone help?
 
Did you try Requery of the Listbox? As the values in the Form changes the Listbox needs to be requeried.
 
I _think_ I did, but as this is all somewhat new to me, I'm not completely sure.

I selected the Form, went to Event, OnLoad, hit the ... to take me to the code builder and have in there:

Private Sub Form_Load()
Me.Requery
End Sub

but thinking about it, do I need to add ListBoxName.Requery?

and I am presuming it needs to be on Form_Load (the parameter to display the correct info on the form [except my new listbox] is already passed, and nothing will change on the form).

Thanks for your help.
 
I _think_ I did, but as this is all somewhat new to me, I'm not completely sure.

I selected the Form, went to Event, OnLoad, hit the ... to take me to the code builder and have in there:

Private Sub Form_Load()
Me.Requery
End Sub

but thinking about it, do I need to add ListBoxName.Requery?

and I am presuming it needs to be on Form_Load (the parameter to display the correct info on the form [except my new listbox] is already passed, and nothing will change on the form).

Thanks for your help.

Code:
Me.Yourlistboxname.Requery
Will requery the listbox only. If that's what you want, then you are correct.
 

Users who are viewing this thread

Back
Top Bottom