Results 1 to 3 of 3

Thread: Subform Update

  1. #1
    Join Date
    May 2006
    Posts
    2

    Question Unanswered: Subform Update

    Hello all,

    I have a FORM called "Riders" which holds a SUBFORM called "SubClasses".

    In "SubClasses" I have a dropdown box, which holds values selected from another form ("Classes"), and upon selecting one of these values, 3 other textboxes are updated automatically.

    To do this I use the following code:
    Code:
    Private Sub Class_AfterUpdate()
    
    Forms("SubClasses").[Type] = DLookup("[Type]", "Classes", "[Class] ='" & Forms![SubClasses]![Class] & "'")
    Forms("SubClasses").[Snr/Jnr] = DLookup("[Snr/Jnr]", "Classes", "[Class] ='" & Forms![SubClasses]![Class] & "'")
    Forms("SubClasses").[Age Group] = DLookup("[Age Group]", "Classes", "[Class] ='" & Forms![SubClasses]![Class] & "'")
    
    End Sub
    This works perfectly fine when I open "SubClasses" seperatly.

    This also works perfectly fine when I open "SubClasses", minimize it, and then open the main FORM, "Riders", and select a value in the SUBFORM.


    Though instead of having to open and minimize the SUBFORM everytime you want to use the main FORM, I placed this code in the "Riders" FORM:

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    DoCmd.OpenForm "SubClasses", acFormDS
    DoCmd.Minimize
    
    End Sub
    This code works fine also.


    The PROBLEM is...
    Now when I open the "Riders" FORM, the SUBFORM is auto opened and minimized, but...
    When I select a value in the subform, it no longer updates the text boxes.


    I have no idea why... It makes no sense to me, works fine seperately and manually, but not when it's done automatically...
    Hopefully someone out there can shead some light on it.
    Thanks in advance

    I have also attached the database.
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    here is an illustration of talking to subforms. you can't pretend they are still standalone forms once they are sitting in a subform control.

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    May 2006
    Posts
    2

    Talking

    Hello izy,


    Thankyou for your response.

    After reading your other post and looking at the sample database I was able to understand that there was no need to open the subform in the background. All I needed was to modify my code to suit it being a subform rarther than a form.

    My new code (for anyone wondering ):

    Code:
    Private Sub Class_AfterUpdate()
       
           
        StringCP = Me.Parent.SubClasses.Form.Class
       
       
       
        TypeCP = DLookup("[Type]", "Classes", "[Class] = '" & StringCP & "'")
        
        Me.Parent.SubClasses.Form.[Type] = TypeCP
        
        
        SnrJnrCP = DLookup("[Snr/Jnr]", "Classes", "[Class] = '" & StringCP & "'")
        
        Me.Parent.SubClasses.Form.[Snr/Jnr] = SnrJnrCP
        
        
        AgeGroupCP = DLookup("[Age Group]", "Classes", "[Class] = '" & StringCP & "'")
        
        Me.Parent.SubClasses.Form.[Age Group] = AgeGroupCP
        
    
    
    End Sub

    Me.Parent.SubForm.Form.Field
    Being the key element.

    Once again thankyou,

    Daren

Posting Permissions

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