Forms and query criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I got several forms that can use the same queries and /or reports and I
would like to some how set an criteria from the forms
I’m tyring the following
DoCmd.OpenQuery “qryNAMEâ€, Acview, , criteria

On my form I would have a txtbox
My code
Dim str as String
Str = Me.txtBoxID.Value
DoCmd.OpenQuery “qryNAMEâ€, , where (qryNAME.NameID = str)
I don’t wish to use the [form]![frmName]![txtBoxID] in the query because
it’s a main query I use all the time and some times I have no criteria.
Can this be done.
 
Hello Gus.

Gus Chuch said:
I got several forms that can use the same queries and /or reports
and I would like to some how set an criteria from the forms.
I'm tyring the following
DoCmd.OpenQuery "qryNAME", Acview, , criteria

You can pass criteriy to forms or reports but not to queries.
On my form I would have a txtbox
My code
Dim str as String
Str = Me.txtBoxID.Value
DoCmd.OpenQuery "qryNAME", , where (qryNAME.NameID = str)
I don't wish to use the [form]![frmName]![txtBoxID] in the query
because it's a main query I use all the time and some times I
have no criteria.
Can this be done.

Not with queries, but you could create a form that is opened in datasheet
view using
DoCmd.OpenForm "frmNAME", acFormDS, , "NameID=" & Me.txtBoxID
 
Back
Top