473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1531
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.cboActivitie s.rowsource = ""
for l = 1 to 6
if l > 1 then
s = s & ";"
endif
s = s & me.cboID.column (l)
next l

me.cboActivitie s.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.cboActivitie s.row source = "Select NameActivityID, ActivityID,
ActivityName From NameActivity Inner Join Activity on
NameActivity.Ac tivityID = Activity.Activi tyID 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.cboActivitie s.rowsource = ""
for l = 1 to 6
if l > 1 then
s = s & ";"
endif
s = s & me.cboID.column (l)
next l

me.cboActivitie s.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.cboActivitie s.row source = "Select NameActivityID, ActivityID,
ActivityName From NameActivity Inner Join Activity on
NameActivity.Ac tivityID = Activity.Activi tyID 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

TableNameActivi ty
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
1950
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 TEXT to a valide item in the Combobox. What I want to do is to select the initial listed item to an item based upon a varrying veriable. For example, the combobox is populated with a list of Users.
4
2116
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 Combobox1.text = " am i using the wrong event
5
3082
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 is in the afterupdate event of the combobox: Me.RecordSource = "QryPFrmInventoryManagement" Me!ItemCount = Me.RecordsetClone.RecordCount & " Items" MsgBox Me.RecordsetClone.RecordCount & " Items"
7
8528
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 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...
3
5610
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 Access to open a report using that query. Can someone give me some pointers on how to do this, or please point me in the direction I need to look for this answer? Thanks,
6
7811
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 the item count correctly
5
9165
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 comboQueryTitle_SelectedIndexChanged handler to, when a new selection is made, update the query and refresh the display. The only problem is that the program seems to inexplicably start with the ..selectedindex property at -1! This makes no sense to me. ...
0
346
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 the subquery, which filters for a particular store. The subform is in continuous mode. So, what you see when you select a store is a list of all the items that that have not been billed for. There is a simple yes no field that filters out all...
2
7155
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 filled in automatically by setting its .Text property equal to the .SelectedValue of the combobox. When the user enters an ID in the textbox the combobox's .SelectedValue is set to the .Text value in the ID textbox. All works fine but it is ...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.