Can we use a parametered query as a form RecordSource?

  • Thread starter Thread starter Mota
  • Start date Start date
M

Mota

Hello;
When i open a form that is bound to a parameter query ,"Please enter
parameter" dialog box appears,even if i set its parameter before.The SQL
string of query and its opening code is:

PARAMETERS [DrugID] Integer;
Select * from DrugsTBL where Did=[DrugID];

Private Sub CmdOpenForm_Click
dim DB as DataBase,QDF as QueryDef
Set DB=DBEngine(0)(0)
set QDF=DB.QueryDefs!OpenQRY
QDF.Parameters(0)=7
DoCmd.OpenForm "FrmBoundToOpenQuery"
End Sub

In MVP.Org/Access Web Dev Ashish expresses this way to use a parameter query
for a recordSource of a DAO.RecordSet,but it really wont work for a form
RecordSource.
Where am i going wrong?Is there another way to do this,other than setting
SQL of that query each time we want to open form?
Thank you so much for your help.
 
You set the Parameter value for the QDF which is valid
only for the (current) QDF, not the saved Query which the
Form uses.

The simpler way is not to use the Parameter in the Query
but use the WhereCondition argument of the OpenForm method
to filter the Form's RecordSource as required.

See Access VB Help on the OpenForm Method, especially the
WhereCondition argument.

HTH
Van T. Dinh
MVP (Access)
 
Back
Top