473,803 Members | 3,424 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
15 2200
puppydogbuddy
1,923 Recognized Expert Top Contributor
Jon,
I think the problem is with the syntax for the wildcard and the ending semi-colon. Try the syntax below for lines #7 and #9.

strSQL = strSQL & “ UNION SELECT “ & Chr(34) & “*” & Chr(34) & “ AS Filter, ‘All Records’ AS [Department]”

strSQL = strSQL & “ WHERE [tbl Site Info].[Site] = ‘” & Forms![frm Main copy]!cboSite & “’;”


If that doesn't get it, can you send me a copy of your mdb, with any sensitive info stripped out? My email is with my profile.
Jun 7 '07 #11
jonosborne
34 New Member
Jon,
I think the problem is with the syntax for the wildcard and the ending semi-colon. Try the syntax below for lines #7 and #9.

strSQL = strSQL & “ UNION SELECT “ & Chr(34) & “*” & Chr(34) & “ AS Filter, ‘All Records’ AS [Department]”

strSQL = strSQL & “ WHERE [tbl Site Info].[Site] = ‘” & Forms![frm Main copy]!cboSite & “’;”


If that doesn't get it, can you send me a copy of your mdb, with any sensitive info stripped out? My email is with my profile.

Ok, its almost started to work, at least the Syntax error has stopped but cboDept doesnt seem to be taking the value of cboSite. Im unable to get your e-mail address from your profile, can you enable access to it and ill forward you the mdb.
Jun 7 '07 #12
puppydogbuddy
1,923 Recognized Expert Top Contributor
Ok, its almost started to work, at least the Syntax error has stopped but cboDept doesnt seem to be taking the value of cboSite. Im unable to get your e-mail address from your profile, can you enable access to it and ill forward you the mdb.
Jon.
I enabled my email, but it is still inaccessable and I will have to find out why. I was able to download my vCard, which also has my email address on it, so you should be able to get it from my vCard.

Before you send me your file, try changing the line that says Me!cboDepartmen t.Requery to Me!cboSite.Requ ery and see what happens, just for kicks.
Jun 7 '07 #13
jonosborne
34 New Member
Ive sent you an email, thanks.
Jun 7 '07 #14
MMcCarthy
14,534 Recognized Expert Moderator MVP
Jon.
I enabled my email, but it is still inaccessable and I will have to find out why. I was able to download my vCard, which also has my email address on it, so you should be able to get it from my vCard.

Before you send me your file, try changing the line that says Me!cboDepartmen t.Requery to Me!cboSite.Requ ery and see what happens, just for kicks.
Hi pdog

The email link doesn't work but the vcard should work fine.

Mary
Jun 13 '07 #15
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hi pdog

The email link doesn't work but the vcard should work fine.

Mary
Thanks, Mary. The vcard link works fine. After I received the application in the email from Jon, I was able to diagnose and fix the problem with these comboboxes. The AfterUpdate event used a union query with a where clause...and the Where clause was placed after the Union Select statement. The Where clause in a Union Query has to be placed with the first select statement or it will not work properly. The correct syntax is shown below.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSite_AfterUpdate()
  2.  
  3. strSQL = ""    'to initialize string variable
  4. strSQL = strSQL & "SELECT Distinct Department AS Filter, Department"
  5. strSQL = strSQL & " FROM [tbl Site Info]"
  6. strSQL = strSQL & " WHERE [tbl Site Info].[Site] = '" & Forms![frm Main copy]!cboSite.Value & "'" 
  7. strSQL = strSQL & " UNION SELECT Distinct " & Chr(34) & "*" & Chr(34) & " AS Filter, 'All Records' AS Department"
  8. strSQL = strSQL & " FROM [tbl Site Info]"
  9. strSQL = strSQL & " Order By Department;"
  10.  
  11. cboDept.RowSource = strSQL
  12.  
  13. Me.Requery
  14.  
  15. End Sub
  16.  
Jun 13 '07 #16

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

Similar topics

0
2079
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
6771
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
2088
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
64652
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
3701
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
3502
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
2676
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
3989
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
5842
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
9703
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
10317
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
10300
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
10069
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
9127
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
7607
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
5503
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...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2974
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.