Listbox not displaying results from query

I have a form based on a table, 2 of the fields on this table are ContactID and ContactName, and I have another form which has no record source, when I press a button on the first form the 2nd form opens, values from ContactID and ContactName are then put into two textboxes on the 2nd form. There is a list box on this form which displays items related to this contact, I use a query as the row source which uses the value that has been put into the textbox as criteria. The code for putting in the two values into the second form from the first is:
Private Sub btnSupplier_Click()
Dim cp As String
Dim ct As String

cp = [ContactID].Value
ct = [Contact].Value

DoCmd.OpenForm "SelectSupplier", acNormal
Forms![SelectSupplier].[txtContactID] = cp
Forms![SelectSupplier].[txtContact] = ct
End Sub

The SQL statement for the listbox is:
SELECT qryContactSupplier.ItemID, qryContactSupplier.ProductName, qryContactSupplier.Description
FROM qryContactSupplier
ORDER BY qryContactSupplier.ProductName;

The problem is that when the 2nd form opens, the results from the query are not displayed, the list box is blank. If I press the refresh button the results are then displayed. I can also make a button that uses the code: Me.lstItems.requery that also works (I dont want to have to do this), but there seems to be no other way to get it to refresh, iv tired putting it in the load event for the form etc.... does not work. Any suggestions?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try requerying the listbox after the form has finished updating.

Or try it on the txtContactID updated event.  it appears you are loading the form and then passing the variables so all the querying is being done prior to you passing the variables.

I;m assuming that qryContactSupplier does some selectio based on the value in txtContactID.  Ifthat is not the case then you need to explain what is going on.

You will have to add requery code to your form open procedure.

The code you need is just :
DoCmd.OpenForm "SelectSupplier", acNormal
Forms![SelectSupplier].[txtContactID] = cp
Forms![SelectSupplier].[txtContact] = ct
Forms![SelectSupplier].listboxnamehere.requery   ' add this line

If you are also adding records manually to an empty SelectSupplier form you need to add the requery statement to the afterupdate event procedure of the txtContactid field.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan89Author Commented:
Cheers peter
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.