Parameters across Forms-VBForums
Results 1 to 11 of 11

Thread: Parameters across Forms

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Parameters across Forms

    From the parent form, I am calling a child form and passing a string from parent to Child. In the Child form, I modify the string and would like to get the updated string in Parent Form.

    Also is it possible to stop the execution of the program in the parent form till the child form doesn't returns the value back to Parent Form.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,238

    Re: Parameters across Forms

    The simplest solution to both is to pass the string as a parameter to a Function in the child form, and for the function to return the new value, eg:

    In the child form:
    Code:
    Public Function DoSomething(strInput as String) as String
      '(code here)
      DoSomething = "new value"
    End Function
    In the parent form:
    Code:
    Dim strValue as String
    strValue = ChildForm.DoSomething("hello")

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Re: Parameters across Forms

    The solutions works but the problem is about updation of the string is dependent on User Input in a Edit Box on the Child Form. So if I pass the value to a User Defined Function in the Child Form, it would not wait for the User Input and execute the complete function as it is.

    Can we have a mechanism to involve the User Input as well.

  4. #4
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: Parameters across Forms

    Is your child form set to 'ShowModal'? If so, this will stop executing code in your parent window until the child window is closed.

    Here's what I usually do to open a form (in your case, the child form):

    Code:
    ' Load child form:
    frmChildForm.load
    
    ' Set any properties in child form:
    frmChildForm.property1 = 'XXXX'
    frmChildForm.property2 = 'XXXX'
    
    ' Show child form:
    frmChildForm.show
    
    ' Get any properties from child form
    property1 = frmChildForm.property1
    property2 = frmChildForm.property2
    
    ' Close child form:
    unload frmChildForm
    For this to work, you need to hide the child form instead of unloading it when it closes (otherwise, you won't be able to get the properties in the form). Hiding the form will return the code to the calling function, but will keep the form loaded so that you can access it's properties.

    So, a 'Close' button on your child form would have the following:
    Code:
    me.Hide
    instead of
    Code:
    unload me
    You don't state which application (or version) you are working in, but this works for me with the programs I am using.

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Re: Parameters across Forms

    Mark,
    Can you please let me know how do we set the child form 'ShowModal'. I have looked in the properties of the Child Form and am not able to get where should the Child Form be set to 'ShowModal'

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Re: Parameters across Forms

    I am using MS Access 2003....

  7. #7
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: Parameters across Forms

    The 'ShowModal' is a property of the form, but I don't use Access, so I can't say that the forms are the same as they are in PPT/Word/Excel/Outlook which I have used. Check to see if there is a 'Modal' property of the form.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Re: Parameters across Forms

    Modal Property is there in MS Access as a Boolean. When I set that property to True it doesn't stops the execution of the program in Parent Form. The control on the Child form comes only when the Parent Form function has been completely executed.

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    60

    Re: Parameters across Forms

    Any response on this please....

  10. #10
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: Parameters across Forms

    Sorry, I don't use Access, so I don't know what would need to be done differntly from the other Office applications. If there's a Modal property, there should be a way to display the form modally, but I am not familiar with Access so I can't help you there.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,238

    Re: Parameters across Forms

    One way to do it in VB6 (which may be supported in Access VBA) is to specify vbModal as a parameter to .Show, eg:
    Code:
    Public Function DoSomething(strInput as String) as String
      '(code here)
      Me.Show vbModal
      DoSomething = "new value"
    End Function

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.