473,790 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Cascading Combo boxes

34 New Member
hi, i hope someone can help, i have read a lot of tutorials relating to this matter but im afraid VBA isnt my strong point and i just need a touch of guidance.

I have one table called [tbl Site Info] which has three fields [Site], [Department] and [Manager]. On a form i have three combo boxes which show data from each field on the table along with an extra 'All Records'. The following code enabling this is in the 'Row Source' of each combo box:

[SELECT [tbl Site Info].[Site] AS Filter, [Site] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Site] FROM [tbl Site Info];]

In conjunction with this, i need/would like the option of limiting the data in the combo boxes based on the selection of the last, i.e. if i select 'UK' from the cboSite box then it will only give me the Departments from the UK in the cboDept box and similarly when i select a department then the cboMgr box will only show the managers associated with that department.

However i need to keep the 'All Records' option as i will need to show all departments in UK, etc...

I tried using the following code in the row source of the cboDept box:

[SELECT [tbl Site Info].[Department] AS Filter, [Department] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Department] FROM [tbl Site Info] WHERE [tbl Site Info].[Site]=Forms![frm Main copy]!cboSite;]

which i believed would only show the departments related to the site, but it did'nt.

Any help would be greatly appreciated,
Jun 6 '07 #1
15 2199
puppydogbuddy
1,923 Recognized Expert Top Contributor
hi, i hope someone can help, i have read a lot of tutorials relating to this matter but im afraid VBA isnt my strong point and i just need a touch of guidance.

I have one table called [tbl Site Info] which has three fields [Site], [Department] and [Manager]. On a form i have three combo boxes which show data from each field on the table along with an extra 'All Records'. The following code enabling this is in the 'Row Source' of each combo box:

[SELECT [tbl Site Info].[Site] AS Filter, [Site] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Site] FROM [tbl Site Info];]

In conjunction with this, i need/would like the option of limiting the data in the combo boxes based on the selection of the last, i.e. if i select 'UK' from the cboSite box then it will only give me the Departments from the UK in the cboDept box and similarly when i select a department then the cboMgr box will only show the managers associated with that department.

However i need to keep the 'All Records' option as i will need to show all departments in UK, etc...

I tried using the following code in the row source of the cboDept box:

[SELECT [tbl Site Info].[Department] AS Filter, [Department] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Department] FROM [tbl Site Info] WHERE [tbl Site Info].[Site]=Forms![frm Main copy]!cboSite;]

which i believed would only show the departments related to the site, but it did'nt.

Any help would be greatly appreciated,
Hi Jon,
You are much closer to what you want then you realize.

All you needed to make the Department combobox work was an afterUpdate event for cboSite that will requery the Department list. In other words, if you want the Department combobox list to reflect only the Departments for the site(s) selected in cboSite, you need to requery the Department list. To do that, place the following code in the afterUpdate event of cboSite.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2.  
  3. Me!cboDept.Requery
  4.  
  5. End Sub
  6.  
Similarly, if you make a selection of a department, you need to requery the managers list to update the managers list based on the department selected.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDept_AfterUpdate()
  2.  
  3. Me!cboMgr.Requery
  4.  
  5. End Sub
  6.  
Jun 7 '07 #2
jonosborne
34 New Member
Thanks Puppydogbuddy,

When i put the code into the 'after_update' of cboSite, there is no difference in the outcome of the cboDept box (i.e. all the results are shown, not just the ones related to that site) . I have tried removing the Row Source details from cboDept but that does not give me any entries.

Is there anything that i am missing?.. if i remove the row source then i wont have the option of 'All Records' which is necessary. Is it possible to have both??

If there is anything you (or anyone else) can suggest then i am open to all ideas, if not then i will keep the boxes as they are.

Again, i do appreciate the help.
Jun 7 '07 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
Jon,
Be patient. We will get there. In the meantime, can you ry the code below in the after update event of cboSite. Just tell me what happens that is different than before. Thanks.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2. cboDept.RowSource = cboSite.RowSource
  3. Me!cboDept.Requery
  4. End Sub
  5.  
Jun 7 '07 #4
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hi Jon,
I see what the problem is now. For cboDept, you should have the following code as the row source:

[SELECT [tbl Site Info].[Department] AS Filter, [Department] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Department] FROM [tbl Site Info];]

and the following code in the after update of cboSite:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2. cboDepartment.RowSource = “[SELECT [tbl Site Info].[Department] AS Filter, [Department] FROM [tbl Site Info] UNION SELECT "*" AS Filter, "All Records" AS [Department] FROM [tbl Site Info] WHERE [tbl Site Info].[Site]=Forms![frm Main copy]!cboSite;]”
  3.  
  4. Me!cboDept.Requery
  5.  
  6. End Sub
  7.  
Jun 7 '07 #5
jonosborne
34 New Member
Hi,

I used the code from your second post and after selecting from cboSite, cboDept then mirrored the information from cboSite.

Now, using the code from your last reply (i amended cboDepartment to cboDept), there seems to be a syntax error in line 2.
Jun 7 '07 #6
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hi,

I used the code from your second post and after selecting from cboSite, cboDept then mirrored the information from cboSite.

Now, using the code from your last reply (i amended cboDepartment to cboDept), there seems to be a syntax error in line 2.
Ok, jon. It may take a couple of tries to get the syntax correct, but we are making progress. I assuming that Site is a text data type. If it isn't, I will need to correct the syntax accordingly. Also, I am trying single quotes around * . If that does not work, I will have to replace the single quotes with the ascii equivalent for double quotes.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2. Dim strSQL As String
  3.  
  4.  
  5. strSQL = “SELECT [tbl Site Info].[Department] AS Filter, [Department]“
  6. strSQL = strSQL & “ FROM [tbl Site Info]”
  7. strSQL = strSQL & “ UNION SELECT ‘*’ AS Filter, ‘All Records’ AS [Department]”
  8. strSQL = strSQL & “ FROM [tbl Site Info]”
  9. strSQL = strSQL & “ WHERE [tbl Site Info].[Site] = ‘” & Forms![frm Main copy]!cboSite & “’” & “;”
  10.  
  11. cboDept.RowSource = strSQL
  12.  
  13. Me!cboDept.Requery
  14.  
  15. End Sub
Jun 7 '07 #7
jonosborne
34 New Member
Site is a text data type, however when pasting the code lines 5-9 are highlighted in red and when selecting the first combo box, once i click on one of the items the same 'Syntax Error' msg box is shown and line 5 is highlighted.
Jun 7 '07 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
Site is a text data type, however when pasting the code lines 5-9 are highlighted in red and when selecting the first combo box, once i click on one of the items the same 'Syntax Error' msg box is shown and line 5 is highlighted.
Ok, Jon.

Please change line 7 from this:
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL & “ UNION SELECT ‘*’ AS Filter, ‘All Records’ AS [Department]”
  2.  
  3. ' to:
  4. strSQL = strSQL & “ UNION SELECT “ & Chr(34) & * & Chr(34) & “ AS Filter, ‘All Records’ AS [Department]”
  5.  

If you still get a syntax error, I need you to hit CTRL + G which will take you to the debug window. The debug window will appear at the bottom of the code window with a carot prompt. At the prompt I need you to type as shown below:
>? strSQL

Access will respond by displaying its interpretation of the SQL syntax that was used. Take a look at it and see if you spot where the syntax was not interpreted correctly. If you can't see anything, copy the string that was displayed and post it here so that I can see it..
Jun 7 '07 #9
jonosborne
34 New Member
Ok, Jon.

Please change line 7 from this:
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL & “ UNION SELECT ‘*’ AS Filter, ‘All Records’ AS [Department]”
  2.  
  3. ' to:
  4. strSQL = strSQL & “ UNION SELECT “ & Chr(34) & * & Chr(34) & “ AS Filter, ‘All Records’ AS [Department]”
  5.  

If you still get a syntax error, I need you to hit CTRL + G which will take you to the debug window. The debug window will appear at the bottom of the code window with a carot prompt. At the prompt I need you to type as shown below:
>? strSQL

Access will respond by displaying its interpretation of the SQL syntax that was used. Take a look at it and see if you spot where the syntax was not interpreted correctly. If you can't see anything, copy the string that was displayed and post it here so that I can see it..

Right, still coming up with a Syntax error. When i goto the debug window and type >?strSQL a message box appears with the words

Compile Error:
Expected: line number or label or statement or end of statement

but nothing else is displayed.

Where am i going wrong?
This is the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2. Dim strSQL As String
  3.  
  4.  
  5. strSQL = “SELECT [tbl Site Info].[Department] AS Filter, [Department]“
  6. strSQL = strSQL & “ FROM [tbl Site Info]”
  7. strSQL = strSQL & “ UNION SELECT “ & Chr(34) & * & Chr(34) & “ AS Filter, ‘All Records’ AS [Department]”
  8. strSQL = strSQL & “ FROM [tbl Site Info]”
  9. strSQL = strSQL & “ WHERE [tbl Site Info].[Site] = ‘” & Forms![frm Main copy]!cboSite & “’” & “;”
  10.  
  11. cboDept.RowSource = strSQL
  12.  
  13. Me!cboDept.Requery
  14.  
  15. End Sub
  16.  
Jun 7 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2078
by: cognoscento | last post by:
I'm currently putting together a database for my work (not an expert by any stretch, so muddling through as best as I can... you know the story...) and I could use some advice and hand-holding I've got a subform with a series of cascading combo boxes (thanks to the Access tutorials on fontstuff.com) that let the user assign categories to items, in this case photos. This is being done to help constrain user selections and keep the...
9
6769
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the second combo to change depending on what values the user selects in the first box, it's just that every time the user changes the first combobox, the second combobox FOR EVERY RECORD goes blank.
6
2086
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user chooses the department they want and then the corresponding surnames from that department can be chosen from the Surname box and then the Forename depending on which Surname they chose. I then have a command button which produces the results of the...
4
64644
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
3
3700
by: buddyr | last post by:
Hello, Yesterday I recieved help with two cascading combo boxes on an access form. I went the link http://www.fontstuff.com/access/acctut10.htm And basically used their first example. Now I may need 3 cascading combo boxes and I cannot figure out how to do that. Can you help? Thank you
4
3497
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields below. tblOrg OrgID, AutoNumber, PK ZipID, Number, FK tblState StateID, AutoNumber, PK
1
2674
kcdoell
by: kcdoell | last post by:
Good Morning: I have a form where I am trying to create cascading combo boxes. I have done this before but I am getting the following error that is throwing me off: Procedure declaration does not match description of event or procedure having the same name. Basically have three tables: One for the Division location:
3
3988
kcdoell
by: kcdoell | last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box: Private Sub CboDivision_AfterUpdate() 'When the Division is selected, the appropriate Segment list will 'display in the drop down list of CboSegment With Me! If IsNull(Me!cboDivision) Then
7
5840
by: Toireasa | last post by:
Hi, Newbie Access developer here, and my first post on this forum, so I might not get everything right - thanks in advance for your help and your patience! I'm using Access 2007, in XP. I'm currently trying to set up a whole pile of cascading combo boxes of different levels of complexity, so I started with the easiest set - and can't even get that to work (even using the tutorial on this site at...
0
9666
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
9512
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
10200
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
10145
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
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
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
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.