Filter a pop-up form

S

Sammy

I added a button to a form which launches a pop-up form.
I want the user to filter the pop-up form based on values
in 2 fields on the pop-up, but I don't want to filter the
main form. How do I do this?
 
T

tina

if you're opening the form with the DoCmd.OpenForm code, add a WHERE clause,
as

DoCmd.OpenForm "MyFormName", , , _
"FieldOne = " & whatever & " And FieldTwo = '" & whatever & "'"

note that that FieldOne is a numeric data type and FieldTwo is text; see the
use of single quotes inside the double quotes for FieldTwo, but not for
FieldOne.
if you're refering to a value in a control in the calling form, replace
whatever< with
Me!MyControlName

hth
 
S

Sammy

Works great! that was a really helpful explanation about
the numeric versus text quotation marks. Thanks.

Now if I want to enter a parameter, ie [enter whatever1]
and [enter whatever2], how would that go?

Thanks.
 
T

tina

you want your user to enter a value, at runtime, for each field to be
filtered? i mean, like in a pop-up box, the way a parameter query works?
if you're calling the OpenForm action from another, already open, form -
then personally, i'd put controls (bound or unbound, as appropriate) on the
form to enter the required values for the filter. in a form control, you
have a lot of control over what and how the value is entered. in a pop-up
box, you have none, really - so you have to validate the value after it's
entered and then perhaps redisplay the popup input box, with appropriate
feedback, etc. seems to me that would be more frustrating to your user.
at any rate, here's how you can use an input box in the code, to get the
parameters:

Dim dblOne As Double, strTwo As String

dblOne = InputBox("Enter instructions/question, etc. for first value.")
strTwo = InputBox("Enter instructions/question, etc. for second value.")

DoCmd.OpenForm "MyFormName", , , _
"FieldOne = " & dblOne & " And FieldTwo = '" & _
strTwo & "'"

you'll get an error if the user enters a letter or symbol for the number
value - see what i mean about controlling the data entry?
and btw, if one of the fields is a date field, the WHERE clause syntax would
be
"FieldName = #" & datevalue & "#"

hth


Sammy said:
Works great! that was a really helpful explanation about
the numeric versus text quotation marks. Thanks.

Now if I want to enter a parameter, ie [enter whatever1]
and [enter whatever2], how would that go?

Thanks.
-----Original Message-----
if you're opening the form with the DoCmd.OpenForm code, add a WHERE clause,
as

DoCmd.OpenForm "MyFormName", , , _
"FieldOne = " & whatever & " And FieldTwo = '" & whatever & "'"

note that that FieldOne is a numeric data type and FieldTwo is text; see the
use of single quotes inside the double quotes for FieldTwo, but not for
FieldOne.
if you're refering to a value in a control in the calling form, replace
Me!MyControlName

hth





.
 
S

Sammy

Thanks, Tina. You are right about filtering through the
main form. I'll stick with that. The input box detail
is helpful, though. I can use it in another place.
-----Original Message-----
you want your user to enter a value, at runtime, for each field to be
filtered? i mean, like in a pop-up box, the way a parameter query works?
if you're calling the OpenForm action from another, already open, form -
then personally, i'd put controls (bound or unbound, as appropriate) on the
form to enter the required values for the filter. in a form control, you
have a lot of control over what and how the value is entered. in a pop-up
box, you have none, really - so you have to validate the value after it's
entered and then perhaps redisplay the popup input box, with appropriate
feedback, etc. seems to me that would be more frustrating to your user.
at any rate, here's how you can use an input box in the code, to get the
parameters:

Dim dblOne As Double, strTwo As String

dblOne = InputBox("Enter instructions/question, etc. for first value.")
strTwo = InputBox("Enter instructions/question, etc. for second value.")

DoCmd.OpenForm "MyFormName", , , _
"FieldOne = " & dblOne & " And FieldTwo = '" & _
strTwo & "'"

you'll get an error if the user enters a letter or symbol for the number
value - see what i mean about controlling the data entry?
and btw, if one of the fields is a date field, the WHERE clause syntax would
be
"FieldName = #" & datevalue & "#"

hth


Works great! that was a really helpful explanation about
the numeric versus text quotation marks. Thanks.

Now if I want to enter a parameter, ie [enter whatever1]
and [enter whatever2], how would that go?

Thanks.
-----Original Message-----
if you're opening the form with the DoCmd.OpenForm
code,
add a WHERE clause,
as

DoCmd.OpenForm "MyFormName", , , _
"FieldOne = " & whatever & " And FieldTwo = '" & whatever & "'"

note that that FieldOne is a numeric data type and FieldTwo is text; see the
use of single quotes inside the double quotes for FieldTwo, but not for
FieldOne.
if you're refering to a value in a control in the calling form, replace
whatever< with
Me!MyControlName

hth


I added a button to a form which launches a pop-up form.
I want the user to filter the pop-up form based on values
in 2 fields on the pop-up, but I don't want to
filter
the
main form. How do I do this?


.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top