Results 1 to 6 of 6
  1. #1
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50

    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    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:	18 
Size:	8.8 KB 
ID:	36447

    However your subform has 4 records. Check its doing what you wanted!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    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, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    OK I have made the main form bound to a table as you suggested and this solves the problem for me. I prefer to keep this as a subform as opposed to making it a stand alone form because I want to include other fields on this form which will actually be a data entry form.


    I could not get your suggestion to add code in the procedure
    Private Sub Form_Current() to work if I kept the main form unbounded. Although this does not matter now.


    Thanks for your help.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Glad to have helped
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

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