JimL said:
'Dim strWhere As String
'strWhere =
"(((tblKnowledge.MachineType)=[frmKnowledge]![cmbMachineType].[value]) AND
((tblKnowledge.SubAssembly)=[frmKnowledge]![cmbSubAssembly].[value]))"
strQryMachType = cmbMachineType.Value
strQryAssy = cmbSubAssy.Value
Dim strWhere As String
strWhere = "(((tblKnowledge.MachineType)=strqrymachtype) AND ((tblKnowledge.SubAssembly)=strqryassy))"
DoCmd.OpenReport "rptknowledge", acViewPreview, "qryknowledge", strWhere
Debug.Print strQryMachType
Debug.Print strQryAssy
These are in the click event for a button on the form. You can see I have
tried a couple of different versions. One uses public variables. I have also
tried running it through macros.
The proper way to reference a form control is...
Forms!NameOfForm!NameOfControl
You also cannot refer directly to variables in a where clause of OpenReport or
in a query. You would need a function that returned the value of the variable.
In both cases you could delimit your statement so that the where clause ends up
with the *value* of the form reference or variable rather then the *name* of the
form reference or variable.
simple example with a numeric value:
Instead of...
strWhere = "[SomeField]=Forms!NameOfForm!NameOfControl"
use
strWhere = "[SomeField]=" & Forms!NameOfForm!NameOfControl