In the OnClick event that opens the second form, build a WhereCondition from
the three parameter fields, using the following format:
If Not IsNull(Field1) Then
WhCond = "Field1 = '" & Field1 & "'"
End If
If Not IsNull(Field2) Then
WhCond = "Field2 = " & Field1
End If
If Not IsNull(Field3) Then
WhCond = "Field3 = " & Field1
End If
This will build only those parameters that are appropriate. Pass the
resultant string WhCond to the WhereCondition argument of the Docmd.OpenForm
code.
Not that the example for Field 1 includes single quotes around the search
value. These are necessary if the search parameter is a string but not for a
numeric. For a date value, convert it to a string using the Format$ VBA
routine and surround it with # characters
Abhijeet said:
Can you suggest some other method to use this possibly with another means to
open my DDM form.
:
Interesting, it should be the same.
:
hmmm I did it but it doesnt seem to be working for some reason. I guess
feeding a Like * as parameter value does not act same as putting Like * in
criteria.
:
Okay, gotcha.
I will assume you have a command button on the first form that opens the
other form. So in the Click event of the command button is where you will
need to do this. I will guess that the Criteria row of your query you have
something like:
[PA Name] = Forms!Form1!txtPAName
If my assumptions are correct, then what I would suggest is you create 3
invisible controls on your first form for the Query to reference, and put the
data in them.
Then, in the Click event of your command button
Me.txtPANameQry = Iif(IsNull(Me.txtPAName), "Like *", Me.txtPAName)
Me.txt FPNumQry = Iif(IsNull(Me.txtFPNum), "Like *", Me.txtFPNum)
Me.txtSmplQry = Iif(IsNull(Me.txtSmpl), "Like *", Me.txtSmpl)
:
Rather... I am using another form to obtain the parameters from the user but
I am feeding the data entered by the user in the condition box of the querry
as Forms![FormName]![Text Entered]
:
How are you using the parameters to open the form? Are you entering them on
another form that opens that form? Are you using them as a where condition?
:
Hi,
I open a form based on three fields. Currently I have all parameters in a OR
kind criteria of the form source. Is it possible that I can use the
parameters to refine my search. eg: I ask user for PA Name or FP Num or Smpl
Num. I want that if user just enters name then i get all records for that
name. If the user types the name and FP Num, i get records for that name
which have the specified FP Num and so on. In short I want to refine my
search with each additional (optional) parameter entered.