Dan89
asked on
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].[tx tContactID ] = cp
Forms![SelectSupplier].[tx tContact] = ct
End Sub
The SQL statement for the listbox is:
SELECT qryContactSupplier.ItemID, qryContactSupplier.Product Name, qryContactSupplier.Descrip tion
FROM qryContactSupplier
ORDER BY qryContactSupplier.Product Name;
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?
Thanks
Dan
Private Sub btnSupplier_Click()
Dim cp As String
Dim ct As String
cp = [ContactID].Value
ct = [Contact].Value
DoCmd.OpenForm "SelectSupplier", acNormal
Forms![SelectSupplier].[tx
Forms![SelectSupplier].[tx
End Sub
The SQL statement for the listbox is:
SELECT qryContactSupplier.ItemID,
FROM qryContactSupplier
ORDER BY qryContactSupplier.Product
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?
Thanks
Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers peter
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.
Me.listbox.Requery