Button click

J

Jacob

I have a form with a subform listing a group of clients from a table. I
am trying to filter the results on a button labeled cty. I want the customer
subform to only list the records based on my selection from a drop down box
above the button. here is my code. Can someone please tell me why it will
not work. All I get is a blank subform.


Me.cus.RowSource = "SELECT tblCustomer.[Customer Name], tblCustomer.Id,
tblCustomer.City, tblCustomer.State, tblCustomer.Contact FROM tblCustomer
WHERE tblCustomer.City=Forms!frmSwitch!cty"

cus is the subform
 
D

Dirk Goldgar

Jacob said:
I have a form with a subform listing a group of clients from a
table. I am trying to filter the results on a button labeled cty. I
want the customer subform to only list the records based on my
selection from a drop down box above the button. here is my code. Can
someone please tell me why it will not work. All I get is a blank
subform.


Me.cus.RowSource = "SELECT tblCustomer.[Customer Name],
tblCustomer.Id, tblCustomer.City, tblCustomer.State,
tblCustomer.Contact FROM tblCustomer WHERE
tblCustomer.City=Forms!frmSwitch!cty"

cus is the subform

If "cus" is a subform, your reference to the RowSource property is
incorrect -- it should be the RecordSource property --plus you need to
drill down to the Form object within the subform control. Try this:

Me.cus.Form.RecordSource = ...

That form of reference should work, provided the code is being executed
on the main form.
 
J

Jacob

My apologies, it is not a subform, it is an unbound list box. I do not know
why I said subform. I have a combo box with the list of cities in it. I also
have a button that when clicked, SHOULD pick up on that combo box and filter
it for the unbound list box. I am sorry for have misleading you.




Dirk Goldgar said:
Jacob said:
I have a form with a subform listing a group of clients from a
table. I am trying to filter the results on a button labeled cty. I
want the customer subform to only list the records based on my
selection from a drop down box above the button. here is my code. Can
someone please tell me why it will not work. All I get is a blank
subform.


Me.cus.RowSource = "SELECT tblCustomer.[Customer Name],
tblCustomer.Id, tblCustomer.City, tblCustomer.State,
tblCustomer.Contact FROM tblCustomer WHERE
tblCustomer.City=Forms!frmSwitch!cty"

cus is the subform

If "cus" is a subform, your reference to the RowSource property is
incorrect -- it should be the RecordSource property --plus you need to
drill down to the Form object within the subform control. Try this:

Me.cus.Form.RecordSource = ...

That form of reference should work, provided the code is being executed
on the main form.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
J

Jacob

I answered my own question. Sorry for the bother but I have it now.


Jacob said:
My apologies, it is not a subform, it is an unbound list box. I do not
know why I said subform. I have a combo box with the list of cities in it.
I also have a button that when clicked, SHOULD pick up on that combo box
and filter it for the unbound list box. I am sorry for have misleading
you.




Dirk Goldgar said:
Jacob said:
I have a form with a subform listing a group of clients from a
table. I am trying to filter the results on a button labeled cty. I
want the customer subform to only list the records based on my
selection from a drop down box above the button. here is my code. Can
someone please tell me why it will not work. All I get is a blank
subform.


Me.cus.RowSource = "SELECT tblCustomer.[Customer Name],
tblCustomer.Id, tblCustomer.City, tblCustomer.State,
tblCustomer.Contact FROM tblCustomer WHERE
tblCustomer.City=Forms!frmSwitch!cty"

cus is the subform

If "cus" is a subform, your reference to the RowSource property is
incorrect -- it should be the RecordSource property --plus you need to
drill down to the Form object within the subform control. Try this:

Me.cus.Form.RecordSource = ...

That form of reference should work, provided the code is being executed
on the main form.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Jacob said:
My apologies, it is not a subform, it is an unbound list box. I do
not know why I said subform. I have a combo box with the list of
cities in it. I also have a button that when clicked, SHOULD pick up
on that combo box and filter it for the unbound list box. I am sorry
for have misleading you.

I take it the combo box is named "cty", and the form it's on is named
"frmSwitch"? If the list box is blank after you reassign the rowsource,
maybe the bound column of the combo box is not equivalent to the City
field in tblCustomer -- for example, maybe it's a numeric ID column
instead of a text "name" column, or vice versa. Check the RowSource and
BoundColumn properties of the "cty" combo box.
 
Top