Results 1 to 8 of 8
  1. #1
    sublevelmonkey is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Posts
    10

    [Access2003/2010] Cascading combo box visibility

    Hi all,



    2nd day with you, 2nd post...

    I've got 2 combo boxes on a form which cascade but I'm struggling to make the dependent box (lowest in the cascade) appear and disappear in line with the condition of the independent (highest in the cascade).

    Closest I can get is to set the visibility of the dependent combo box to 'No' and have it turned to 'Yes' in the After_Update event of the independent box that populates the dependent box.

    But then if I change the value in the independent box, the dependent combo box remains visible, even though there is no data in it.

    I think I need to tell the program: "Starting with dependent combo box hidden, If item selected in independent combo box initiates dependent combo box, show dependent combo box. If not, keep dependent combo box hidden. If selection in independent combo box changes from 'If' condition to 'If not' condition, re-hide dependent combo box."

    It's frustrating to be beginning to understand the language the program is speaking but not to know any of the right words to talk with it!

    Anyway, here's the code I'm using:

    Private Sub cboPrefix_AfterUpdate()
    cboGMCMSuffix.Visible = True
    Me.cboGMCMSuffix.RowSource = "SELECT GMCMSuffix FROM" & _
    " tblGMCMSuffix WHERE PrefixID = " & Me.cboPrefix & _
    " ORDER BY GMCMSuffix"
    Me.cboGMCMSuffix = Me.cboGMCMSuffix.ItemData(0)

    End Sub


    Also, on a related note (and if I could figure this out, I might not have bothered sorting the main issue but hey, I want it done right!), if I delete any text in either box, I can still input data that's not been pulled from the underlying tables.

    Yaaarggghhh!

    Any help'd be much appreciated.
    Last edited by sublevelmonkey; 01-18-2012 at 10:30 AM. Reason: solved

  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,518
    Along the lines of:

    Code:
    If Len(Me.ComboName & vbNullString) > 0 Then
      'set row source and make visible
    Else
      'make not visible
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sublevelmonkey is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Posts
    10
    Thanks again pbaldy,

    Got it working now

    I think I can 'read' it as well, all except the vbNullString part.

    Could you explain what that is doing in the code?

    All helps with my learning process (a steep curve!).

  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,518
    vbNullString is an efficient VBA way of referring to a zero length string (""). This

    If Len(Me.ComboName & vbNullString) > 0 Then

    is a common test to check for both Null and a zero length string ("") by combining the contents of the combo (which could be Null) with a zero length string so that testing for it's length will work. The Len() function would return Null on a Null field, so combining it with vbNullString ensures it will always return a numeric value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    sublevelmonkey is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Posts
    10
    OK.

    I think I understand

    So this is a way to utilize content present by analysing a numerical value it could be recognized as (such as the number of letters that comprise it) rather than trying to use the 'meaningful' (to a human) information.

    i.e. it's easier for the program to say "there are 0 letters where I'm looking and so I'll do this' rather than "it doesn't say Z, X, Y, or W, so I'll do this"

    Wish I'd learnt this language at school rather than a smattering of Spanish. Computers will rule the world eventually, the Spanish have had their shot!

    Thanks again.
    Last edited by sublevelmonkey; 01-18-2012 at 11:02 AM. Reason: typo

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The problem is that a human just sees an "empty" control. That control could be Null or it could have a zero length string in it. Both look the same to the human but different to the computer. If you test for Null:

    If IsNull(Me.Whatever) Then

    a control with a ZLS will not be caught. If you test for a ZLS:

    If Me.Whatever = "" Then

    the control with Null will not be caught. The test above is a way to test for both. Here's a FAQ my friend Jason wrote on the topic:

    http://www.baldyweb.com/NullEmptyEtc.htm

    Warning, he gets scholarly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    sublevelmonkey is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Posts
    10
    Thanks pbaldy,

    Following on from this, any suggestions as to why this code would not be working in Access2003?

    If I try and use the dropbox on the form in 2003 (which I need for compatability purposes), I get the error message:

    "The expression After Update you entered as the event property setting produced the following error: Object or class does not support the set of events"

    Does this mean that what you've helped me do in 2010 can't be done in 2003?

    Or was there a change in the coding language (or maybe just a new 'accent'!) between Access2003/2010?


    Thanks again!

    p.s. Another piece of code I added working in 2010 also does not work in 2003, giving the same error message.

    This was a button for duplicating entered text into another part of the same form:

    Private Sub CollectorIsDonor_Click()
    * * DonorOrganisation.Value = CollectorOrganisation.Value
    * * DonorTitle.Value = CollectorTitle.Value
    * * DonorFirst.Value = CollectorFirst.Value
    * * DonorMiddle.Value = CollectorMiddle.Value
    * * DonorLast.Value = CollectorLast.Value
    End Sub

    So I'm leaning towards an error in language, what are the chances that both things I want to do can't be done in 2003!
    Last edited by sublevelmonkey; 01-19-2012 at 05:18 AM. Reason: addition for clarification

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I don't see anything in either process that wouldn't work in any version. Does it point to a particular line?
    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 Box Help
    By euphoricdrop in forum Forms
    Replies: 3
    Last Post: 04-12-2011, 05:35 PM
  2. Visibility based on Combo selection
    By jlclark4 in forum Forms
    Replies: 1
    Last Post: 12-22-2010, 11:42 AM
  3. cascading combo
    By rexb in forum Forms
    Replies: 9
    Last Post: 10-26-2009, 04:10 PM
  4. cascading combo form
    By tonysomerset in forum Forms
    Replies: 0
    Last Post: 08-27-2008, 02:10 AM
  5. Cascading Combo Box
    By nywi6100 in forum Forms
    Replies: 0
    Last Post: 10-23-2006, 01:45 PM

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