VBA / Macro to filter

K

Khalil Handal

Hi,
How can I record a macro (or have a VBA code) to filter data depending on
two fields in a form.

I want to use a seperate form to identify these 2 fields.

Note:
I was able to do it following the steps in the help option in access.

Thanks in advance
 
J

John W. Vinson

Hi,
How can I record a macro (or have a VBA code) to filter data depending on
two fields in a form.

I want to use a seperate form to identify these 2 fields.

Note:
I was able to do it following the steps in the help option in access.

Thanks in advance

It's not necessary to use either a macro or VBA code. Just reference the form
with the criteria in the Query, using

=Forms![NameOfYourForm]![NameOfYourControl]

as a criterion.

John W. Vinson [MVP]
 
K

Khalil Handal

Thanks .

John W. Vinson said:
Hi,
How can I record a macro (or have a VBA code) to filter data depending on
two fields in a form.

I want to use a seperate form to identify these 2 fields.

Note:
I was able to do it following the steps in the help option in access.

Thanks in advance

It's not necessary to use either a macro or VBA code. Just reference the
form
with the criteria in the Query, using

=Forms![NameOfYourForm]![NameOfYourControl]

as a criterion.

John W. Vinson [MVP]
 
K

Khalil Handal

Hi,
I have a qryName based on tbl address and put :
=[Forms]![frmName]![FirstName]
in the criteria of the query called qryName
In the form property the source was qryName and when I opend the form
frmName it was empty.
Copy the:
=[Forms]![frmName]![FirstName]
in the filter property and still have the same empty form with no records.
Need more explanation / Details please.

Thanks


John W. Vinson said:
Hi,
How can I record a macro (or have a VBA code) to filter data depending on
two fields in a form.

I want to use a seperate form to identify these 2 fields.

Note:
I was able to do it following the steps in the help option in access.

Thanks in advance

It's not necessary to use either a macro or VBA code. Just reference the
form
with the criteria in the Query, using

=Forms![NameOfYourForm]![NameOfYourControl]

as a criterion.

John W. Vinson [MVP]
 
J

John W. Vinson

Hi,
I have a qryName based on tbl address and put :
=[Forms]![frmName]![FirstName]
in the criteria of the query called qryName
In the form property the source was qryName and when I opend the form
frmName it was empty.
Copy the:
=[Forms]![frmName]![FirstName]
in the filter property and still have the same empty form with no records.
Need more explanation / Details please.

What's in Forms!frmName!FirstName? Is the form frmName open at the time you
run the query? Why would tblAddress (which presumably contains addresses, not
names) have a field for FirstName?

Perhaps you could post the SQL view of the query and indicate what tables it
is based on.

John W. Vinson [MVP]
 
K

Khalil Handal

hi,
tblAddress is a sample table that has FirstName and LastNameName fields with
Address. I am using it for practice.
The query I am using is derived from the table tbladdress. I want the form
frmName to get only the filtered record from that query according to the
firstName.
In the Form!frmName property I have the following: (I think it is not
correct):
Record Source: qryName
Filter: =Forms!{frmName]![FirstName]

In the Query qryName under the colomn of FirstName Field in the criteria
area:
=Forms![frmName]![FirstName]

I am missing Something!!! Am I????

Khalil




John W. Vinson said:
Hi,
I have a qryName based on tbl address and put :
=[Forms]![frmName]![FirstName]
in the criteria of the query called qryName
In the form property the source was qryName and when I opend the form
frmName it was empty.
Copy the:
=[Forms]![frmName]![FirstName]
in the filter property and still have the same empty form with no records.
Need more explanation / Details please.

What's in Forms!frmName!FirstName? Is the form frmName open at the time
you
run the query? Why would tblAddress (which presumably contains addresses,
not
names) have a field for FirstName?

Perhaps you could post the SQL view of the query and indicate what tables
it
is based on.

John W. Vinson [MVP]
 
J

John W. Vinson

hi,
tblAddress is a sample table that has FirstName and LastNameName fields with
Address. I am using it for practice.
The query I am using is derived from the table tbladdress. I want the form
frmName to get only the filtered record from that query according to the
firstName.
In the Form!frmName property I have the following: (I think it is not
correct):
Record Source: qryName
Filter: =Forms!{frmName]![FirstName]

In the Query qryName under the colomn of FirstName Field in the criteria
area:
=Forms![frmName]![FirstName]

I am missing Something!!! Am I????

You're doing it backwards. You are trying to use frmName as both the criterion
to filter the table, and also to display the results of that query! It can't
be both!

You need some unbound (nothing in its Control Source) textbox or combo box to
serve as the criterion; and then, separately, a bound control to display the
result of the query.

John W. Vinson [MVP]
 
K

Khalil Handal

Thanks for making it clear.


John W. Vinson said:
hi,
tblAddress is a sample table that has FirstName and LastNameName fields
with
Address. I am using it for practice.
The query I am using is derived from the table tbladdress. I want the form
frmName to get only the filtered record from that query according to the
firstName.
In the Form!frmName property I have the following: (I think it is not
correct):
Record Source: qryName
Filter: =Forms!{frmName]![FirstName]

In the Query qryName under the colomn of FirstName Field in the criteria
area:
=Forms![frmName]![FirstName]

I am missing Something!!! Am I????

You're doing it backwards. You are trying to use frmName as both the
criterion
to filter the table, and also to display the results of that query! It
can't
be both!

You need some unbound (nothing in its Control Source) textbox or combo box
to
serve as the criterion; and then, separately, a bound control to display
the
result of the query.

John W. Vinson [MVP]
 

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