Results 1 to 7 of 7
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Combo Box Values to Go Blank on Lost Focus

    Hi,



    I have a Main form with a Subform1 which then has a Subform2.

    On this Subform2, I have combo boxes that generate values based on values I chose in other combo boxes on the Subform2.

    When I click away from the subform2 (that is, open up a different form while making subform2 no longer visible) and then come back to subform2, the values are still presented in those combo boxes.

    How do I make it so that the combo boxes are blank upon return (re-visibility) of the subform2? Particularly, I know you have to use VBA and use the LostFocus event, but I have tried this and nothing seems to work. Perhaps someone can help me write the appropriate code for this.

    Thanks,

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Those comboboxes are UNBOUND?

    Me.comboboxname = Null

    Put that in the same event that sets the form not visible and opens other form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I put the code in the same event that sets the form to not visible and opens the other form. Thing is, that code is written for the Main form and does not recognize the control (that is, Me. (list) ) does not show the control. If I were to type the control name it does not recognize the member and I get an error.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So you have to reference thru 2 levels of subforms? I've never had to do that. Maybe:

    Me.subformcontainername.Form.subformcontainername. Form.comboboxname = Null

    I always give subform containers different name from the objects they hold.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    It worked. Thank you!

    I didn't realize that you needed the code within the actual main form vs within the subform itself, but that makes sense.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The code does not have to be behind main form but it does have to be in some event, such as the button click I presume you are using to open other form.

    If you tried the subform2 LostFocus event that probably did not work because it is not open as an independent form or because there are controls that have focus. When control has focus the form does not, therefore the form cannot lose focus, the control does.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I see what you are saying, thanks again.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-18-2014, 02:20 PM
  2. Replies: 20
    Last Post: 06-24-2013, 03:14 PM
  3. Blank Values in Combo Box Selection
    By CementCarver in forum Access
    Replies: 1
    Last Post: 02-28-2013, 01:11 PM
  4. Combo Box showing Blank Values
    By glen in forum Access
    Replies: 5
    Last Post: 11-24-2012, 09:44 AM
  5. hide a list box on lost focus
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 08-18-2012, 10:32 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