473,387 Members | 1,863 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,387 software developers and data experts.

ComboBox Query question

I have two tables
The first has a ID (key) field and enteries for Name
The second has a ID field (tied to the first) and then 6 fields for
activities. Called Activity1, Activity2, etc etc

I would like to make a form that when they selected their Name from a
combo box, another combobox would take its selections from a query tied
to their name and put their 6 Activities into the second combo box.
Writing the query is no problem, I just have all 7 fields it, where the
Name field is "Like NameSelection" on the form
but I cannot seem to make access take the next 6 fields and use their
data to fill the combo box.

Any advice is apperciated. Thank you!

Jun 6 '06 #1
6 1513
If the query fueling the combobox is Select ID, Activity1, Activity2...,
this will build a rowsource showing the six activities

dim l as long
dim s as string
me.cboActivities.rowsource = ""
for l = 1 to 6
if l > 1 then
s = s & ";"
endif
s = s & me.cboID.column(l)
next l

me.cboActivities.Rowsource = s

The real question is why you would use a table with columns like Activity1,
Activity2, etc. Any time you see repeating (usually numbered) field names,
that is a tip-off that the data is not normalized properly. YOu need a
second table that contains the ID and 1 Activity field. Then you can have
as many activities as you want for any name, and listing those activities
doesn't make you do odd things such as I coded above. Then it look more
like this:

me.cboActivities.row source = "Select NameActivityID, ActivityID,
ActivityName From NameActivity Inner Join Activity on
NameActivity.ActivityID = Activity.ActivityID Where NameActivity.ID = " &
me.lboID & " Order By ActivityName"

Here, you have a listbox of names (ID, Name), and a combobox of activities
for that name.

If you want to explore this approach more, post back.
Jun 6 '06 #2
This approach definatly interests me. I am just learning access and
this is my first project with tables that are relational.
So Your saying I would want 2 tables, one with a Key field and a Name
field, and the second table with a non-key number ID field, and a
Activity field
So basically NameTable Row one would be:
1 | JonnyRotten
2 | Joe Blow

TableActivity would be
1 | Made shiney in access
1 | Reseached thing on the net
1 | Had a meeting
1 | Fixed a computer
2 | Swept
2 | Made a widget

etc etc

TableName would have a 1 to many relation with Table activity, correct?

So when it comes to making a combo box, I would take the Key field from
TableName, and run my query for that number in the ID field, so my
combobox would have all that numbered items in it.

Rick Wannall wrote:
If the query fueling the combobox is Select ID, Activity1, Activity2...,
this will build a rowsource showing the six activities

dim l as long
dim s as string
me.cboActivities.rowsource = ""
for l = 1 to 6
if l > 1 then
s = s & ";"
endif
s = s & me.cboID.column(l)
next l

me.cboActivities.Rowsource = s

The real question is why you would use a table with columns like Activity1,
Activity2, etc. Any time you see repeating (usually numbered) field names,
that is a tip-off that the data is not normalized properly. YOu need a
second table that contains the ID and 1 Activity field. Then you can have
as many activities as you want for any name, and listing those activities
doesn't make you do odd things such as I coded above. Then it look more
like this:

me.cboActivities.row source = "Select NameActivityID, ActivityID,
ActivityName From NameActivity Inner Join Activity on
NameActivity.ActivityID = Activity.ActivityID Where NameActivity.ID = " &
me.lboID & " Order By ActivityName"

Here, you have a listbox of names (ID, Name), and a combobox of activities
for that name.

If you want to explore this approach more, post back.


Jun 6 '06 #3
OK, I am pretty stoked here.
I have the relational tables working. I can make the query work.
Now I have my form with Name as a combobox that pulls its data from the
Names Table
Then I have my Activity ComboBox that should be pulling its information
from the query, which it kind of is.
The problem is, if I change the Name field.. the data in Activity does
not change. How can I make this happen?

Jun 6 '06 #4
How are you loading the Activity combobox rowsource?
Jun 6 '06 #5
Pretty close. But it's 3 tables.

TableName
NameID (autonumber)
Name

TableActivity
ActivityID (autonumber)
ActivityName

TableNameActivity
NameActivityID (autonumber)
NameID
ActivityID

Make sense?
Jun 6 '06 #6
I have a query set up that takes the name from one combo box and uses
that to find all the matchine activities from the second table.

Rick Wannall wrote:
How are you loading the Activity combobox rowsource?


Jun 7 '06 #7

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

Similar topics

10
by: Mr. B | last post by:
I've been seeking the solution to this. But can't figure it out (sounds simple enough). When you Populat a ComboBox, you can select the initial displayed items on startup simply by setting the...
4
by: Newbee | last post by:
Hola I wanted to kno how to clear the current text that is displayed in my combobox I am filling it with a query which is run against my database I have tried this but it not work ...
5
by: Steve | last post by:
I have an unbound combobox in the form header of a continuous form. The selection in the combobox sets the where clause in a querydef which determines QryPFrmInventoryManagement. The following code...
7
by: Nicolae Fieraru | last post by:
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...
3
by: Ray Holtz | last post by:
Access 2003 (2000 file format) question: When I run a form, it opens with only a combo box and a button to execute a query based on the criteria tha is selected in the combobox. Then I need...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
5
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the...
0
by: bcreighton | last post by:
I have created a bound subform on an unbound masterform linked together with a common field (A store's identification number) using an unbound combobox on the masterform and an invisible field on...
2
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.