-
Apr 11th, 2012, 07:39 AM
#1
Thread Starter
Member
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.
-
Apr 11th, 2012, 07:55 AM
#2
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")
-
Apr 11th, 2012, 08:26 AM
#3
Thread Starter
Member
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.
-
Apr 11th, 2012, 08:41 AM
#4
Addicted Member
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.
-
Apr 11th, 2012, 09:11 AM
#5
Thread Starter
Member
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'
-
Apr 11th, 2012, 09:32 AM
#6
Thread Starter
Member
Re: Parameters across Forms
I am using MS Access 2003....
-
Apr 11th, 2012, 09:59 AM
#7
Addicted Member
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.
-
Apr 11th, 2012, 10:14 AM
#8
Thread Starter
Member
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.
-
Apr 12th, 2012, 03:42 AM
#9
Thread Starter
Member
Re: Parameters across Forms
Any response on this please....
-
Apr 12th, 2012, 07:31 AM
#10
Addicted Member
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.
-
Apr 12th, 2012, 07:55 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|