473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Changing rowsource when dropdown the combobox

Hi All,

I am trying to change the rowsource of a combobox when I click on it. I
played with many events, associated with the form and the combobox, but
still haven't figured out what is the way of doing it.
I have a table with products, tblProducts, some of them are Active while
others are Inactive.
The form shows all the products purchased by a customer, both Active and
Inactive in a ComboBox, cbProducts.
My client wants to view all the products purchased by a customer in this
combobox. But when he clicks on a combobox, in the dropdown should show the
active or inactive products, depending on the state of a checkbox.
So, I set the rowsource of the combobox to tblProducts and the combobox
shows all the products purchased in the continuous form. When I click on the
combobox and the dropdown shows up, if the checkbox is set to "show only
active products in dropdown", I want to change the rowsource to a query,
qryActiveProducts. When I leave the combobox, I want to show again in the
combobox all the active and inactive products

Any help appreciated

Regards,
Nicolae


Nov 13 '05 #1
7 8456
On Mon, 12 Jul 2004 13:25:38 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
Hi All,

I am trying to change the rowsource of a combobox when I click on it. I
played with many events, associated with the form and the combobox, but
still haven't figured out what is the way of doing it.
I have a table with products, tblProducts, some of them are Active while
others are Inactive.
The form shows all the products purchased by a customer, both Active and
Inactive in a ComboBox, cbProducts.
My client wants to view all the products purchased by a customer in this
combobox. But when he clicks on a combobox, in the dropdown should show the
active or inactive products, depending on the state of a checkbox.
So, I set the rowsource of the combobox to tblProducts and the combobox
shows all the products purchased in the continuous form. When I click on the
combobox and the dropdown shows up, if the checkbox is set to "show only
active products in dropdown", I want to change the rowsource to a query,
qryActiveProducts. When I leave the combobox, I want to show again in the
combobox all the active and inactive products


Nicolae,

Clarify something for me. If every time you enter the combobox you
want the drop down list to reflect the value of the checkbox, why
would you go through the effort of resetting the combobox dropdown so
that it no longer accurately reflects the value of the checkbox?
Wouldn't that just be extra work that is transparent because when you
reenter the combobox you will again reset the rowsource to accurately
reflect the checkbox?

Maybe that question will help you figure out what events to use.

My thinking is that you take the AfterUpdate event of the checkbox and
you do something like:

Private Sub chkActiveOnly_AfterUpdate()
Dim strAllProductsSQL As String
' Set the rowsourse SQL to use if chkActiveOnly is not checked
' watch word wrap
strAllProductsSQL = "Select tblProductsID, tblProductsName from " & _
"tblProducts order by tblProductsName"

If chkActiveOnly = -1 Then ' We want only the actives
Dim db As DAO.Database
Set db = CurrentDb()
Dim qryDefs As DAO.QueryDefs
Dim qryDef As DAO.QueryDef
For Each qryDef In db.QueryDefs
If qryDef.Name = "qryActiveProducts" Then
Me.cbProducts.RowSource = qryDef.SQL
End If
Next qryDef
db.Close
Set db = Nothing
Else
cbProducts.RowSource = strAllProductsSQL
End If

End Sub

Try that.

mike
Nov 13 '05 #2
Hi Nicolae,
Place this code behind the form:

Private Sub ToggleCombo(fCheckState as Boolean)
If fCheckState = True Then
Me!cbProducts.RowSource = "qryActiveProducts"
Else
Me!cbProducts.RowSource = "tblProducts"
End If
End Sub

Behind the AfterUpdate event of the check box copy this code:
ToggleCombo Me!YourCheckBoxName

In the Exit Event of your combo box use this code:
Me!YourCheckBoxName = False
ToggleCombo Me!YourCheckBoxName

The first is a sub routine that changes the row source of your combo box
depending on the state of the check box. This is called whenever you click
the checkbox or when you leave the combo box. Also when you leave the combo
box the check box is set back to False so the sub routine can call the
appropriate row source.

What I do in this type of situation is don't set the combo's rowsource using
the properties but call the ToggleCombo with the form's On Current event.

Stewart
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I am trying to change the rowsource of a combobox when I click on it. I
played with many events, associated with the form and the combobox, but
still haven't figured out what is the way of doing it.
I have a table with products, tblProducts, some of them are Active while
others are Inactive.
The form shows all the products purchased by a customer, both Active and
Inactive in a ComboBox, cbProducts.
My client wants to view all the products purchased by a customer in this
combobox. But when he clicks on a combobox, in the dropdown should show the active or inactive products, depending on the state of a checkbox.
So, I set the rowsource of the combobox to tblProducts and the combobox
shows all the products purchased in the continuous form. When I click on the combobox and the dropdown shows up, if the checkbox is set to "show only
active products in dropdown", I want to change the rowsource to a query,
qryActiveProducts. When I leave the combobox, I want to show again in the
combobox all the active and inactive products

Any help appreciated

Regards,
Nicolae

Nov 13 '05 #3
Hi Mike,

The problem is like this: there is a form which can navigate through the
customers. A continous subform shows all the products bought by the
customers, both active and inactive. There is a navigator for the customers
and one navigator for the products purchased. The user of the database can
add in the same form and subform either a new user or a new product
purchased (or both). When somebody wants to add a new product purchased,
they fill in the details in the subform and in the combobox they want to see
only the active products (there are lots of inactive products and it is
pointless to display them when adding a new product). But sometimes the same
main form can be used to check what products have been purchased over the
time by customer X. And my client doesn't want to see blank comboboxes
corresponding to inactive products.
I can't use the event of the checkbox, because when I open the form, the
combobox is set by default on "show only active products". If my combobox
rowsource is set to the query, it shows only active products, all the
inactive products will be shown as blank. If I have the rowsource as
tblProducts, when I dropdown the combobox, the event on the checkbox won't
be triggered and the dropdown will contain all products.

Thanks for your help

Regards,
Nicolae

"Mike Preston" <mb**************@pacbell.net> wrote in message
news:40****************@news.INDIVIDUAL.NET...
On Mon, 12 Jul 2004 13:25:38 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
Hi All,

I am trying to change the rowsource of a combobox when I click on it. I
played with many events, associated with the form and the combobox, but
still haven't figured out what is the way of doing it.
I have a table with products, tblProducts, some of them are Active while
others are Inactive.
The form shows all the products purchased by a customer, both Active and
Inactive in a ComboBox, cbProducts.
My client wants to view all the products purchased by a customer in this
combobox. But when he clicks on a combobox, in the dropdown should show theactive or inactive products, depending on the state of a checkbox.
So, I set the rowsource of the combobox to tblProducts and the combobox
shows all the products purchased in the continuous form. When I click on thecombobox and the dropdown shows up, if the checkbox is set to "show only
active products in dropdown", I want to change the rowsource to a query,
qryActiveProducts. When I leave the combobox, I want to show again in the
combobox all the active and inactive products


Nicolae,

Clarify something for me. If every time you enter the combobox you
want the drop down list to reflect the value of the checkbox, why
would you go through the effort of resetting the combobox dropdown so
that it no longer accurately reflects the value of the checkbox?
Wouldn't that just be extra work that is transparent because when you
reenter the combobox you will again reset the rowsource to accurately
reflect the checkbox?

Maybe that question will help you figure out what events to use.

My thinking is that you take the AfterUpdate event of the checkbox and
you do something like:

Private Sub chkActiveOnly_AfterUpdate()
Dim strAllProductsSQL As String
' Set the rowsourse SQL to use if chkActiveOnly is not checked
' watch word wrap
strAllProductsSQL = "Select tblProductsID, tblProductsName from " & _
"tblProducts order by tblProductsName"

If chkActiveOnly = -1 Then ' We want only the actives
Dim db As DAO.Database
Set db = CurrentDb()
Dim qryDefs As DAO.QueryDefs
Dim qryDef As DAO.QueryDef
For Each qryDef In db.QueryDefs
If qryDef.Name = "qryActiveProducts" Then
Me.cbProducts.RowSource = qryDef.SQL
End If
Next qryDef
db.Close
Set db = Nothing
Else
cbProducts.RowSource = strAllProductsSQL
End If

End Sub

Try that.

mike

Nov 13 '05 #4
On Mon, 12 Jul 2004 16:18:00 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
Hi Mike,

The problem is like this: there is a form which can navigate through the
customers. A continous subform shows all the products bought by the
customers, both active and inactive.
What is the annotation on the subform's information that identifies
whether a product is active or inactive?
There is a navigator for the customers
and one navigator for the products purchased.
By "navigator" I assume you mean a combobox that, when selected,
brings up certain information that is specific to the selection,
right? Why would you have a navigator on the subform with respect to
the customers? Wouldn't that be on the main form? Suffice it to say
that I just am having a hard time trying to understand what is going
on.
The user of the database can
add in the same form and subform either a new user or a new product
purchased (or both).
The form both displays information with respect to an existing
customer and allows the user the ability to add a new customer? The
subform both displays information on existing products and it allows
the user to add new products?

This is a mighty powerful form and subform you have there.
When somebody wants to add a new product purchased,
they fill in the details in the subform and in the combobox they want to see
only the active products (there are lots of inactive products and it is
pointless to display them when adding a new product).
I would certainly agree with that.

It sounds like the subform has a recordsource that you need to modify
to exclude the inactive products. Is that right?
But sometimes the same
main form can be used to check what products have been purchased over the
time by customer X.
Unfortunately, this doesn't make too much sense to me. Is there a
second sub-form that identifies the historical purchases?
And my client doesn't want to see blank comboboxes
corresponding to inactive products.
This would be rectified by eliminating the inactive products from the
subforms recordsource.
I can't use the event of the checkbox, because when I open the form, the
combobox is set by default on "show only active products".
But you yourself said you wanted to use the checkbox's selection as
the driving force. I don't think the fact that the checkbox is in one
state or another modifies the efficacy of checking the checkbox for a
change in value and then modifying your rowsource (or record source in
the case of a subform) appropriately.
If my combobox
rowsource is set to the query, it shows only active products, all the
inactive products will be shown as blank. If I have the rowsource as
tblProducts, when I dropdown the combobox, the event on the checkbox won't
be triggered and the dropdown will contain all products.
I'm sorry, but I haven't the foggiest idea what you are driving at
here. Maybe somebody else can pick up where you left off (trying to
get a single check box to control a single combobox's rowsource), add
in the above and come up with something.

Good luck.

mike

"Mike Preston" <mb**************@pacbell.net> wrote in message
news:40****************@news.INDIVIDUAL.NET...
On Mon, 12 Jul 2004 13:25:38 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
>Hi All,
>
>I am trying to change the rowsource of a combobox when I click on it. I
>played with many events, associated with the form and the combobox, but
>still haven't figured out what is the way of doing it.
>I have a table with products, tblProducts, some of them are Active while
>others are Inactive.
>The form shows all the products purchased by a customer, both Active and
>Inactive in a ComboBox, cbProducts.
>My client wants to view all the products purchased by a customer in this
>combobox. But when he clicks on a combobox, in the dropdown should showthe >active or inactive products, depending on the state of a checkbox.
>So, I set the rowsource of the combobox to tblProducts and the combobox
>shows all the products purchased in the continuous form. When I click onthe >combobox and the dropdown shows up, if the checkbox is set to "show only
>active products in dropdown", I want to change the rowsource to a query,
>qryActiveProducts. When I leave the combobox, I want to show again in the
>combobox all the active and inactive products


Nicolae,

Clarify something for me. If every time you enter the combobox you
want the drop down list to reflect the value of the checkbox, why
would you go through the effort of resetting the combobox dropdown so
that it no longer accurately reflects the value of the checkbox?
Wouldn't that just be extra work that is transparent because when you
reenter the combobox you will again reset the rowsource to accurately
reflect the checkbox?

Maybe that question will help you figure out what events to use.

My thinking is that you take the AfterUpdate event of the checkbox and
you do something like:

Private Sub chkActiveOnly_AfterUpdate()
Dim strAllProductsSQL As String
' Set the rowsourse SQL to use if chkActiveOnly is not checked
' watch word wrap
strAllProductsSQL = "Select tblProductsID, tblProductsName from " & _
"tblProducts order by tblProductsName"

If chkActiveOnly = -1 Then ' We want only the actives
Dim db As DAO.Database
Set db = CurrentDb()
Dim qryDefs As DAO.QueryDefs
Dim qryDef As DAO.QueryDef
For Each qryDef In db.QueryDefs
If qryDef.Name = "qryActiveProducts" Then
Me.cbProducts.RowSource = qryDef.SQL
End If
Next qryDef
db.Close
Set db = Nothing
Else
cbProducts.RowSource = strAllProductsSQL
End If

End Sub

Try that.

mike



Nov 13 '05 #5
Hi Mike,
"Mike Preston" <mb**************@pacbell.net> wrote in message
news:40****************@news.INDIVIDUAL.NET...
On Mon, 12 Jul 2004 16:18:00 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
Hi Mike,

The problem is like this: there is a form which can navigate through the
customers. A continous subform shows all the products bought by the
customers, both active and inactive.
What is the annotation on the subform's information that identifies
whether a product is active or inactive?

In tblProductDetails there is a code for products. If the code = 55 then
that is an inactive products. All the other numbers are for valid prooducts.
There is a navigator for the customers
and one navigator for the products purchased.
By "navigator" I assume you mean a combobox that, when selected,
brings up certain information that is specific to the selection,
right? Why would you have a navigator on the subform with respect to
the customers? Wouldn't that be on the main form? Suffice it to say
that I just am having a hard time trying to understand what is going
on.

No, I was referring at the form and subform. Each of them has a navigator,
which allows to move through records.
The navigator on the form is for customers and the navigator on the subform
is for products.
The user of the database can
add in the same form and subform either a new user or a new product
purchased (or both).


The form both displays information with respect to an existing
customer and allows the user the ability to add a new customer? The
subform both displays information on existing products and it allows
the user to add new products?

No, the main form is for customers. You can add a new customer there. The
subform allows you to add a new purchase. This is a mighty powerful form and subform you have there.
When somebody wants to add a new product purchased,
they fill in the details in the subform and in the combobox they want to seeonly the active products (there are lots of inactive products and it is
pointless to display them when adding a new product).
I would certainly agree with that.

It sounds like the subform has a recordsource that you need to modify
to exclude the inactive products. Is that right?

No, it isn't right. They want to view the inactive products when the
combobox is in its normal (not dropped down state)
Only when the combobox is dropped down, the recordsource has to contain only
the active products.
But sometimes the same
main form can be used to check what products have been purchased over the
time by customer X.


Unfortunately, this doesn't make too much sense to me. Is there a
second sub-form that identifies the historical purchases?

Both form and subform display the information in continous mode.
And my client doesn't want to see blank comboboxes
corresponding to inactive products.
This would be rectified by eliminating the inactive products from the
subforms recordsource.

Here is where my problem begins, because if I remove the inactive products
from there, I won't see the inactive products which have been purchased by
customers before...
I can't use the event of the checkbox, because when I open the form, the
combobox is set by default on "show only active products".
But you yourself said you wanted to use the checkbox's selection as
the driving force. I don't think the fact that the checkbox is in one
state or another modifies the efficacy of checking the checkbox for a
change in value and then modifying your rowsource (or record source in
the case of a subform) appropriately.

Yes, when I drop down the combobox, it has to check the state of the
checkbox and if the checkbox is true, it should show all products, and if
not, it should show only active products (in dropdown)
If my combobox
rowsource is set to the query, it shows only active products, all the
inactive products will be shown as blank. If I have the rowsource as
tblProducts, when I dropdown the combobox, the event on the checkbox won'tbe triggered and the dropdown will contain all products.


I'm sorry, but I haven't the foggiest idea what you are driving at
here. Maybe somebody else can pick up where you left off (trying to
get a single check box to control a single combobox's rowsource), add
in the above and come up with something.

Good luck.

mike


Thank you for your help. I might not have explained too well what the
situation is and what I require. If you want to have a further look, I could
send you a tiny database, to see for yourself what my problem is.

Regards,
Nicolae
Nov 13 '05 #6
On Fri, 16 Jul 2004 09:26:56 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
But you yourself said you wanted to use the checkbox's selection as
the driving force. I don't think the fact that the checkbox is in one
state or another modifies the efficacy of checking the checkbox for a
change in value and then modifying your rowsource (or record source in
the case of a subform) appropriately.
Yes, when I drop down the combobox, it has to check the state of the
checkbox and if the checkbox is true, it should show all products, and if
not, it should show only active products (in dropdown)
That is what the original suggestion I made would do. Have you tried
it?
Thank you for your help. I might not have explained too well what the
situation is and what I require. If you want to have a further look, I could
send you a tiny database, to see for yourself what my problem is.


If you can post it somewhere for downloading, that would be better.

mike
Nov 13 '05 #7
"Nicolae Fieraru" <no****@please.cxm> wrote in
news:40******@duster.adelaide.on.net:
Hi Mike,

The problem is like this: there is a form which can navigate
through the customers. A continous subform shows all the
products bought by the customers, both active and inactive.
There is a navigator for the customers and one navigator for
the products purchased. The user of the database can add in
the same form and subform either a new user or a new product
purchased (or both). When somebody wants to add a new product
purchased, they fill in the details in the subform and in the
combobox they want to see only the active products (there are
lots of inactive products and it is pointless to display them
when adding a new product). But sometimes the same main form
can be used to check what products have been purchased over
the time by customer X. And my client doesn't want to see
blank comboboxes corresponding to inactive products.
I can't use the event of the checkbox, because when I open the
form, the combobox is set by default on "show only active
products". If my combobox rowsource is set to the query, it
shows only active products, all the inactive products will be
shown as blank. If I have the rowsource as tblProducts, when I
dropdown the combobox, the event on the checkbox won't be
triggered and the dropdown will contain all products.

Thanks for your help

Regards,
Nicolae

Sounds to me that you don't need the checkbox at all. What you
want is to have the combobox display the active items only on a
new record, I'd use the form's .NewRecord to change the
..rowsource, putting the code in the OnCurrent event.

Bob Quintal

"Mike Preston" <mb**************@pacbell.net> wrote in message
news:40****************@news.INDIVIDUAL.NET...
On Mon, 12 Jul 2004 13:25:38 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
>Hi All,
>
>I am trying to change the rowsource of a combobox when I
>click on it. I played with many events, associated with the
>form and the combobox, but still haven't figured out what is
>the way of doing it. I have a table with products,
>tblProducts, some of them are Active while others are
>Inactive. The form shows all the products purchased by a
>customer, both Active and Inactive in a ComboBox,
>cbProducts. My client wants to view all the products
>purchased by a customer in this combobox. But when he clicks
>on a combobox, in the dropdown should show the >active or inactive products, depending on the state of a
>checkbox. So, I set the rowsource of the combobox to
>tblProducts and the combobox shows all the products
>purchased in the continuous form. When I click on the >combobox and the dropdown shows up, if the checkbox is set
>to "show only active products in dropdown", I want to change
>the rowsource to a query, qryActiveProducts. When I leave
>the combobox, I want to show again in the combobox all the
>active and inactive products


Nicolae,

Clarify something for me. If every time you enter the
combobox you want the drop down list to reflect the value of
the checkbox, why would you go through the effort of
resetting the combobox dropdown so that it no longer
accurately reflects the value of the checkbox? Wouldn't that
just be extra work that is transparent because when you
reenter the combobox you will again reset the rowsource to
accurately reflect the checkbox?

Maybe that question will help you figure out what events to
use.

My thinking is that you take the AfterUpdate event of the
checkbox and you do something like:

Private Sub chkActiveOnly_AfterUpdate()
Dim strAllProductsSQL As String
' Set the rowsourse SQL to use if chkActiveOnly is not
checked ' watch word wrap
strAllProductsSQL = "Select tblProductsID, tblProductsName
from " & _
"tblProducts order by
tblProductsName"

If chkActiveOnly = -1 Then ' We want only the actives
Dim db As DAO.Database
Set db = CurrentDb()
Dim qryDefs As DAO.QueryDefs
Dim qryDef As DAO.QueryDef
For Each qryDef In db.QueryDefs
If qryDef.Name = "qryActiveProducts" Then
Me.cbProducts.RowSource = qryDef.SQL
End If
Next qryDef
db.Close
Set db = Nothing
Else
cbProducts.RowSource = strAllProductsSQL
End If

End Sub

Try that.

mike



Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
8
by: bbdata | last post by:
ok i have a problem here and not much time to play round. have a form bound to a table. one of the combos is bound to a field Agents. i have active and retired agents. thing is, i want to be able...
2
by: Tom | last post by:
I have the following tables: TblState StateID State TblCounty CountyID StateID County
4
by: Blake D. | last post by:
I have two tables (tblClients and tblEmployees). Field in tblClient uses the PK of tblEmployee as a lookup. Currently, the PK is a text field containing the person's name. I want to add a...
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As...
4
by: Wally | last post by:
This is probably a very simple problem, but I can't figure out the coding for it. I have a list box that displays one of my tables. I'd the user to be able to reorder the items in the list box...
1
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a...
4
by: Wayne | last post by:
I've used a data field as the rowsource for a combo box many times. The main advantage that I see is that a separate table of say, "Customers" does not have to be constantly updated. When a new...
6
by: troy_lee | last post by:
I have a continuous form that has one combo box (cbo1) with the selectable values of "Removal" and "Installation". I would like to change another combo box (cbo2) value list based on the selection...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.