Raposa,
You can make a Form variable reference the form after you open it:
Air Code:
Dim frm as Form
DoCmd.Open acForm, "MyForm"
Set frm = Forms!MyForm
frm.Message= "Hello form!"
set frm = Nothing
This will not close the form when the frm is set to nothing. It will,
however, open the Form before applying the Property. This happens fast
enough that the user won't see the difference, but if there is code in
your OnOpen or OnLoad Events that depend on the Property, then those
events won't see it as it hasn't been set yet. An option to this is to
have the post Property code run in a Public Sub in the form, then you
could do this:
Air Code:
Dim frm as Form
DoCmd.Open acForm, "MyForm"
Set frm = Forms!MyForm
frm.Message= "Hello form!"
frm.MySub 'This is the Public Sub in the Form
set frm = Nothing
Hope that helps
--
Bri
Raposa Velha wrote:[color=blue]
> Hi Steve.
> Good tips, thanks!
> The instability argument it's a strong one, strong enough to make me give up
> of this approach. A pity, because this makes the application more similar to
> a set of black boxes. Actually this idea come because I wanted to use the
> properties capability. The thing is if I use the DoCmd.OpenForm to open the
> form, can I still set the custom properties before opening the form? After
> the user presses OK (for example), it's no problem reading the custom
> properties: it's just a matter of hiding the form instead of closing it.
>
> RV
>
>
> "Steve Jorgensen" <nospam@nospam.nospam> wrote in message
> news:kmp4t0pjfm9ojqe1tum07ec8tllbj89odd@4ax.com...
>[color=green]
>>You have discovered one of the many limitations of the technique of
>>instantiating forms using the New keyword. In general, you can find
>>another
>>way to do the same thing, and avoid the problem.
>>
>>In the rare cases when the techniquer really does add enough value to
>>compensate for the added complexity and instability (e.g. the form will
>>close
>>if the code gets reset), at least make sure you write your code in an
>>event-driven manner so that you don't need your code to halt and wait for
>>the
>>form to close. Instead, use events on the form to trigger the follow-up
>>action.
>>
>>Note that you can bootstrap a form reference by having the form reference
>>itself, so it doesn't close when the procedure that opens it exits (the
>>alternative is some sort of messy open instances collection). Just make
>>sure
>>the form sets its self-reference to Nothing on Form_Close, so all
>>resources
>>are freed up.
>>
>>On 28 Dec 2004 10:52:56 -0800,
jmclopes@hotmail.com (Raposa Velha) wrote:
>>
>>[color=darkred]
>>>Hello to all!
>>>
>>>Does any of you want to comment the approach I implement for
>>>instantiating a form? A description and an example follow.
>>>
>>>Cheers,
>>>RV
>>>jmclopesAThotmail.com replace the AT with the thing you know ;-)
>>>
>>>After discovering that access 2000 support form properties (I'm a
>>>newbie, alright :-) ), I was pleased with the idea of organizing my
>>>code with some object oriented approach. Something like:
>>>
>>>- instantiate a form
>>>- set form properties
>>>- display the form
>>>- read form properties
>>>- do whatever required
>>>
>>>Then I realized (at least I didn't find how) that I couldn't open the
>>>form in a way that the procedure execution would stop until the form
>>>is closed. With the following code, the form is displayed but the
>>>procedure continues its execution and, when it ends, the form is
>>>destroyed:
>>>
>>>Sub my_proc()
>>> Dim f As New Form_my_form
>>> f.Message = "Hello form!" ' Message it's a property I added to
>>>the form
>>>
>>> 'The user would enter some text in a textbox,
>>> 'which the form returns with the property Message
>>> f.visible=true
>>>
>>> MsgBox f.Message
>>> Set f = Nothing
>>>End Sub
>>>
>>>So I solved this problem as follows. The idea is after the form is
>>>displayed, the procedure loops while the form is visible. The form is
>>>made not visible when the user presses the OK in that form.
>>>
>>>
>>>'-------- NEW VERSION of my_proc() -----------
>>>Sub my_proc()
>>> Dim f As New Form_my_form
>>> f.Message = "Hello form!" ' Message it's a property I added to
>>>the form
>>>
>>> 'The user would enter some text in a textbox,
>>> 'which the form returns with the property Message
>>> f.Modal = True ' one can set the form to modal to have a popup
>>>behaviour
>>> f.visible=true
>>> While f.Visible
>>> DoEvents
>>> Wend
>>>
>>> MsgBox f.Message
>>> Set f = Nothing
>>>End Sub
>>>
>>>
>>>
>>>
>>>'-------- MY_FORM PROCEDURES -----------
>>>Private Sub btnOk_Click()
>>> Me.Visible = False
>>>End Sub
>>>
>>>Private Sub Form_Unload(Cancel As Integer)
>>> 'Don't unload the form, just hide it so the properties
>>> 'are still available to the caller
>>> If Me.Visible Then
>>> 'only cancel the unload if the form isn't hidden
>>> Me.Visible = False
>>> Cancel = 1
>>> End If
>>>End Sub[/color]
>>[/color]
>
>[/color]