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")
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.
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:
instead of
You don't state which application (or version) you are working in, but this works for me with the programs I am using.
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'
Re: Parameters across Forms
I am using MS Access 2003....
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.
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.
Re: Parameters across Forms
Any response on this please....
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.
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