473,473 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access 2007 basic Cascading Combo box problems

2 New Member
I have hit my head against the wall for too long on this, and redone the code based on different samples and each time get new problems so hopefully somebody can assist.

I have a form with a combo box for department (combo133) and a combo box for signing authority (combo139). The source table for both department (field department) and signing authority (field "name_Last_First") is called authority. The output of the form is being saved to a table WO with fields called "Originating Department" and "signing Authority"

I've added the following to my originating department after update:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo133_AfterUpdate()
  2. On Error Resume Next
  3. combo139.rowsource = "Select distinct Name_Last_first " & _
  4. "From Authority " & _
  5. Where Department ='" & me.combo133 & "' " & _
  6. "Order by Name_Last_First"
  7. End Sub
each time I'm getting VBA errors "Compile error: Expected: end of statement" highlighting "department"

Another error I have seen is on the main form once the initial combo value is selected I receive "Syntax error (missing operator) in query expression 'department=Security'.

Any pointers would be greatly appreciated.

Thanks.
Oct 7 '13 #1
3 1255
zmbd
5,501 Recognized Expert Moderator Expert
You've stumbled upon one of my pet peeves by building the criteria string directly to the command/property - and it's not your fault because that's how a majority of examples show how to create these things.

Instead I suggest that you build the string first and then use the string in the command. Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.

So to use your code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo133_AfterUpdate() 
  2.    DIM strSQL as string
  3. '
  4.    On Error Resume Next 
  5. '
  6.    strSQL = "SELECT DISTINCT Name_Last_first " & _ 
  7.       "FROM Authority " & _ 
  8.       "WHERE Department = '" & me.combo133 & "' " & _ 
  9.       "ORDER BY Name_Last_First;" 
  10.  '>>(Made two additional changes here:
  11.       'Added a double quote before the WHERE clause
  12.       'Added the closing semicolon
  13. '
  14. 'now you can insert a debug print here for troubleshooting
  15. ' - press <ctrl><g> to open the immediate window
  16. ' - you can now cut and paste this information for review!
  17. '
  18. debug.print "Your criteria = " & strSQL
  19. '
  20. 'now use the string in your code:
  21.    combo139.rowsource = strSQL
  22. End Sub
If you will make these little changes and if you are still haveing issues, then post back the resolved string we can help you tweak the code.
Oct 7 '13 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Z has already found and fixed the problem that stopped your code working (The missing double-quote (")). He has also given very good advice as to work generally with SQL and that you should formulate the string first (See How to Debug SQL String).

The semi-colon (;) is not absolutely necessary in Jet SQL (The SQL used in Access) so will not throw up any errors. Nevertheless it wouldn't hurt to use it generally as it can make your code more portable in the long-term.
Oct 8 '13 #3
infoman206
2 New Member
Thank you VERY much for the assistance - it is often the small things with code that can cause us to run around in a circle for too long. Have a great week.
Oct 8 '13 #4

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

Similar topics

0
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 ...
2
by: codeWarrior007 | last post by:
Hi, I created an access database with cascading combo boxes with the information for each combo box stored in separate tables. I wanted to put the database on SharePoint 2007 but when I put it up...
4
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...
3
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...
4
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...
7
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...
8
by: 20028431 | last post by:
This is driving me mad! I have been trying for 3 days now to work out how to do this with no success. I have tables for Customer, Bookings, Entertainment, Act, Agent, and several others. I...
8
by: jerken | last post by:
Im working in Access 2007 using two Combo boxes to select a category then product type. I am trying to get a couple fields to be displayed based on what the values are in the combo boxes. I have the...
1
by: L Chapman | last post by:
I have a form "form2" witha combobox called "namesearch" that lists names from the table "students" once a student is selected from the combobox i want to use a button to only show reports of that...
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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.