Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    11

    Unanswered: Updating combobox in sub subform

    Hi;

    I'm new here and I'm a beginner with access 2003.

    I have a form which is a 3 levels of form... mainform, subform and sub subform.

    cboCategory will be populated based on two combobox namely cboGender and cboGrade. I did this succesfully without any problem. All of this combobox are in the subform.

    Now I have another combobox, cboEvent which is in sub subform. I want this cboEvent to be populated based on changes in the cboCategory (in the subform). However it works only at the first record. When I'm going to add or move to the next record, the category have no change no matter what is happening to cboCategory.

    I hope someone will have time to look at my Db and please let me know what is wrong with it. Thank you so much.
    Attached Files Attached Files
    Last edited by Zul77; 02-19-10 at 09:02.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You have to requery the combo cboEvent after updating the value of cboCategory:
    Code:
    Private Sub cboCategory_AfterUpdate()
    
        Me.[tblStudentEvent SubForm].Form.cboEvent.Requery
        
    End Sub
    Generally speaking, it would be a good idea to avoid spaces and other "special" characters when you name your objects (e.g. tblStudentEvent_SubForm instead of tblStudentEvent SubForm), as well as to give meaningful names to the controls (e.g. Cmd_AddStudent instead of Command33), this would spare you a lot of troubles when debugging or when you have to review the code, sometimes a long time after you wrote it.
    Have a nice day!

  3. #3
    Join Date
    Feb 2010
    Posts
    11
    Thank you very much for your reply and it's work. However is there any possibility or any way that I don't need to click cboCategory to make the cboEvent been requery?

    It is because the cboCategory will be already populated based on the gender and student's grader. So there will be only one category shown in cboCategory, hence no need to click for cboCategory anymore.

    About the naming in Access, thanks for your advice. For now I just follow the default name created by Access to avoid from being confused (I'm just a beginner).

    Thanks again.

  4. #4
    Join Date
    Feb 2010
    Posts
    11
    Oooppss.... I got it. I put the above syntax in the cboGender and cboGrade after update event.

    However there is one more problem. After fill in a few students' records, when I go to the previous students' records, I found the event information (in sub subform) gone missing. When I put in the event information for the student, the event information for the other students then gone missing. Can you tell me how to settle this problem?

    Thanks.

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You could always write a centralized function in the form [frmStudent subform] that you would call to requery the combo everytime you need it:
    Code:
    Public Function RequeryCboEvent()
    
        Me.[tblStudentEvent SubForm].Form.cboEvent.Requery
    
    End Function
    From the main form:
    Code:
        Me.[tblStudent subform].Form.RequeryCboEvent
    From the subform:
    Code:
        RequeryCboEvent
    Another solution would be to have a public handler on the combo (create a public instance of):
    Code:
    Option Compare Database
    Option Explicit
    Public ComboEvent As ComboBox
    
    Private Sub Form_Load()
    
        Set ComboEvent = Me.[tblStudent subform].Form.[tblStudentEvent subform].Form.cboEvent
        
    End Sub
    Now from frmMain:
    Code:
        ComboEvent.Requery
    From [frmStudent subform]:
    Code:
        Me.Parent.ComboEvent.Requery
    And, of course, from [frmStudentEvent subform]:
    Code:
        Me.cboEvent.Requery
    Have a nice day!

  6. #6
    Join Date
    Feb 2010
    Posts
    11
    Thank you so much. I have added this code to the sub subform:

    Private Sub Form_Current()
    cboEvent.Requery
    End Sub

    And it works. Thanks again for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •