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?

[Webinar] Streamline your web hosting managementRegister Today

peter57rConnect With a Mentor Commented:
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.

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.

Dan89Author Commented:
Cheers peter
All Courses

From novice to tech pro — start learning today.