Results 1 to 4 of 4

Subform does not recognise main form values passed as globals/openarg

  1. #1
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    46

    Question Subform does not recognise main form values passed as globals/openarg


    Please find attached my sample database that demonstrates the problem I am having.


    I am trying to display values in a subform using the link master and child fields.
    Only the subform does not seem to recognise the main form values that have been passed to the form as global variables or as openarg


    To show the problem do these steps:
    1. Open the form frmMain
    2. Type number 198 into the text box and click OK.


    A pop up form opens and displays the main form values passed in as globals/openarg but does not display the parameters in the subform.


    Now when you comment out the main form values passed in as globals etc and uncomment the same values that are hardcoded, the parameters in the subform are displayed.


    Note - To comment/uncomment open frmAddNewScheduledReportInstance in design view and go to Visual Basic.


    I would appreciate if someone could explain what is the issue here and suggest a fix.


    Many thanks in anticipation.
    Attached Thumbnails Attached Thumbnails CodeCommentedOut.JPG  
    Attached Files Attached Files

  2. #2
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,703
    Although you have manually set the parent/child fields they have no effect because your main form is unbound.
    If you click on either parent or child in the property sheet you will see an error message

    If I understand correctly what you want to do, try adding the following to the subform:

    Code:
    Private Sub Form_Current()
        Me.Parameter = Parent.txtReference
    End Sub
    Click image for larger version. 

Name:	Capture.PNG 
Views:	13 
Size:	8.8 KB 
ID:	36447

    However your subform has 4 records. Check its doing what you wanted!
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment

  3. #3
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    46
    Hi Colin,


    Thanks for your reply. I must admit that I only partially understand your response. I recognize that because the main form is unbound there is no automatic linking between the parent form and the subform even though I manually set the parent/child fields.


    I have three fields on the main form that correspond to the same three fields in the subform although they are not visible on the subform.


    So I understood you are suggesting that I add a Form_Current procedure in the subform and add the following code?


    Option Compare Database
    Option Explicit


    Private Sub Form_Current()


    Me.Report_ID = Parent.txtReference
    Me.Version = Parent.txtVersion
    Me.Instance = Parent.txtInstance

    End Sub


    However this does not seem to work. Alternatively, I tried replacing Parent with the full reference e.g. Me.Reference = Forms!frmAddNewScheduledReportInstance.txtReferenc e and this does not work either.


    I would like to see the four records displayed in the subform when I enter 198 in the textbox on frmMain.


    I am sorry I am not fully understanding this and appreciate your help.

  4. #4
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,703
    OK let me try again
    You can link a form & subform using parent and child fields from the record source of each form.
    You cannot link the controls in each form - only the fields
    However, your main form is unbound - it has no record source so it can't be linked to the fields in the subform.

    If your main form was bound to a table or query then it would be possible
    But I'm not really clear why you have both form & subform in this case - why not just the subform as a standalone form?

    What I suggested in my last post was all I meant you to do.
    I don't know that will do what you want as I don't really know what you want.

    Anyway, I've attached it so you can decide for yourself

    HTH
    Attached Files Attached Files
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment

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

Similar Threads

  1. Replies: 10
    Last Post: 07-05-2017, 10:31 AM
  2. Replies: 19
    Last Post: 09-25-2015, 09:26 PM
  3. Replies: 3
    Last Post: 04-03-2015, 03:36 PM
  4. Replies: 3
    Last Post: 01-18-2013, 10:44 AM
  5. search main form using the values in the subform
    By haritbhasin in forum Forms
    Replies: 1
    Last Post: 10-23-2012, 10:48 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
  •  
Tech Forums: Microsoft Office Forums