> I am developing an Access 2000 form, and I want to populate a
databound list box using a saved query that requires parameters.
Is there any way to do this? I tried creating a DAO querydef
object and setting the parameters, and then assigned the querydef
object to the list box "rowsource" property. This did not work.
I use a function to pass parameters to queries most of the time. If I need
to pass a file path or some other string that may contain quotes or
potential problem characters, then I use a parameter query.
If you can get the value needed from a control, or put it in a hidden
textbox on a form, you can use this function in the query.
example:
SELECT * FROM qryMyQuery WHERE MyField_ID = QryPrm("frmMain", "txtMyId")
Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String, _
Optional ByVal strSubFrm As String, Optional ByVal strSubFrmCtl As
String) _
As Variant
If Len(strSubFrmCtl) = 0 Then
If Len(strSubFrm) = 0 Then
QryPrm = Forms(strFrm).Controls(strCtl)
Else
QryPrm = Forms(strFrm).Controls(strCtl).Form.Controls(strSu bFrm)
End If
Else
QryPrm =
Forms(strFrm).Controls(strCtl).Form.Controls(strSu bFrm).Form.Controls(strSubFrmCtl)
End If
End Function