Results 1 to 9 of 9
  1. #1
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91

    VBA Codin of cascading Combo Boxes

    Hi

    I have been trying tocorrect my coding with no avail. I have a combo box called 'Area' - Source: [Dept_code] which I want to use to filter in the combo box called 'Course' - Source: [Course Title], both are from the table [Annual Programme].

    At the moment I get the error 'sub or function not defined' and it highlights 'Area' in the coding (I've bolded it and underlined it here).
    [Private Sub Area_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT Course_Title " & _
    "FROM tblAnnual_Programme"
    WHERE Dept_code = "" & Me.Area & "ORDER BY Course"
    Me.Course.RowSource = strSource
    Me.Course = vbNullString
    End Sub]



    I would be grateful if someone could tell me what I'm missing as I am at a loss at present.
    Many thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Your concatenation is all off. Conquer one thing at a time. For now, try to do it all on one line. When you get it working, you can try splitting it up.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you, may leave them as separate boxes as have no problem with that but doesn't matter how I code it I can't get it to work as cascading so must be missing something very obvious, seem to be going round in circles.

    Thanks for the help.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    What does it look like on one line? What is the data type of Dept_code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    The data type of Dept_code is text.

    I have changed the second combo box to a more appropriate one.

    At present I have got thus far
    [Me.coursecode.RowSource = "SELECT Parent AOS FROM" & _
    " tblAnnualProgInput WHERE dept_code = " & Me.Area & _
    " ORDER BY Parent AOS"]

    But it still is not happy I have the message 'Syntax error (missing operator) in query expression 'Parent AOS'
    Last edited by scoe; 10-29-2013 at 04:50 AM.

  6. #6
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Sorted: Added a query to each combo box to filter the choices, works a dream.....Thank you for your help.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Glad you sorted it. Because your field is text you needed delimiters, like

    Me.coursecode.RowSource = "SELECT [Parent AOS] FROM" & _
    " tblAnnualProgInput WHERE dept_code = '" & Me.Area & _
    "' ORDER BY Parent AOS"

    note also the brackets around the field name, required because of the inadvisable space.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you for that, I tried delimiters but I obviously was not placing them correctly.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problemo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. cascading Combo boxes
    By Chatholo in forum Forms
    Replies: 2
    Last Post: 08-09-2013, 01:39 AM
  2. Cascading Combo boxes
    By finsmith in forum Forms
    Replies: 10
    Last Post: 02-12-2013, 09:37 AM
  3. Sum of Cascading Combo Boxes
    By alonewolf23 in forum Forms
    Replies: 2
    Last Post: 11-20-2011, 02:10 PM
  4. Cascading combo boxes
    By combine21 in forum Forms
    Replies: 3
    Last Post: 12-02-2010, 12:57 PM
  5. Cascading Combo Boxes
    By desireemm1 in forum Programming
    Replies: 1
    Last Post: 10-05-2009, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums